Skip to content

Multiple image retrive from database

Keshwar Gupta

Asked Apr 22, 2014, 8:28 AM EDT2 answers
Share
LinkedInX
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.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Umesh Kumar
    0
    C#
    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; }
    0
  • Umesh Kumar
    0
    Else you can use the below code

    Create a regular HTML img element like so:

    Code
    <img runat="server" id="image"  />

    And in code behind do this:

    Code
    image.src="data:image/png;base64,"+Convert.ToBase64String(imageBytes);

    Where imageBytes is a byte[]

    You are done. The image will be displayed.

    0