kiran
kiran

Reputation: 305

show image from database

i want to show binary data ( image) from database without using handler

   var imgLogo = cid.Tables[0].Rows[0]["Logo"].ToString();

could you please suggest me the way to do. here is my aspx content

how i can set imageUrl from codebehind? i have tried below one but its not working

            Byte[] bytes = (Byte[])cid.Tables[0].Rows[0]["Logo"];
            Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "image/jpg";
            Response.BinaryWrite(bytes); 

how i can set the imageUrl from this?

thanks in advance.

Upvotes: 0

Views: 224

Answers (1)

Ahmed ilyas
Ahmed ilyas

Reputation: 5822

Well the code you have only sets the image to be written to the response. you need to use the ASP.NET Image control, then use a Handler to serve up the image.

The handler would be the one to read the image bytes from the database, then read it into the Response like you have done somewhat.

take a look:

Retrieve image from database into a image tag

Upvotes: 1

Related Questions