Hi,
How to retrive multiple image from database in Asp.net on Image control.
Database column have sstudent id(int), name(varchar),photo(varBinarymax),sig(varbinarymax) & doc(varbinarymax) in Sql Server,
I have inserted all details in Database successfully. But unable to retrive these on Web Page,
Kindly assist.
Multiple image retrive from database
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Umesh Kumar122 pointsPosted Apr 23, 2014, 7:32 AM EDT
Hi Basically you can use this function to convert your byte data from your Db and pass it back to the image propertty of asp.net image control. public static System.Drawing.Image ByteArrayToImage(byte[] bArray) { if (bArray == null) return null; System.Drawing.Image newImage; try { using (MemoryStream ms = new MemoryStream(bArray, 0, bArray.Length)) { ms.Write(bArray, 0, bArray.Length); newImage = System.Drawing.Image.FromStream(ms, true); } } catch (Exception ex) { newImage = null; //Log an error here } return newImage; }Umesh Kumar122 pointsPosted Apr 23, 2014, 7:33 AM EDT
Create a regular HTML img element like so:
And in code behind do this:
Where imageBytes is a
byte[]You are done. The image will be displayed.