I'm trying to display an image that's stored in a SQL Server database. The ContentType and binary data are being returned but the image is coming up as a broken image. To test that the data is being retrieved I tried outputting the content type.


It is getting the corect data i.e. "image/pjpeg"

Then I tried Response.write for the binary data returned


It is outputting printing "System.Byte[]"

Am I right in saying the data is being returned from the SPROC?

Here is the code...

if (adm.HasRows)
                while (adm.Read())
                 // Response.Write(adm["Image_MIME_type"].ToString());
                        Response.ContentType = adm["Image_MIME_type"].ToString();
                Response.Write("Reaer has no rows");


Load the image into a byte array.
Pass the byte array into a memory stream
Pass the memory stream into a new or existing bitmap.

byte[] b = (byte[])adm["Image_image"];
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
                        stream.Write(b, 0, b.Length);

Bitmap bmp = new Bitmap(stream);

Error checking, null checking, etc needs to be added, left out for simplicity


This article has been dead for over six months. Start a new discussion instead.