How can I display an image from SQL Server using ASP.NET?

后端 未结 2 1199
逝去的感伤
逝去的感伤 2020-12-19 17:00

Here is my class (product.cs) where is the method to insert the image:

public static void InsertProductIMG(byte[] image, string contentType) 
{
   string cs          


        
2条回答
  •  天命终不由人
    2020-12-19 17:29

    Create a web page that returns the image. You would select the bytes from the database (as you have already code written to insert, I think you know how to select). Once you have the bytes, you need to set the mime type and write the bytes to the response stream.

    var bytesFromDatabase = getImageFromDatabase();
    context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite(bytesFromDatabase);
    

    Edit:

    Just use a img tag with the cource tet to the aforementioned aspx web page. Eg:

    image
    

提交回复
热议问题