title: Retrieve Images from sql server database
body: <p>i am storing images to the database. How to retrieve all the images from the database.</p>
  
  <p>Eg: select images from imagetable</p>
  
  <p>Problem:</p>
  
  <p>Data Logic:</p>
  
  <pre><code>           while (dr.Read())
            {
               ///Check for null
                if (!dr.IsDBNull(0))
               {
                  try
                  {
                      ///Converting the image into bitmap
                      byte[] photo = (byte[])dr[0];
                      ms = new MemoryStream(photo);
                      Bitmap bm = new Bitmap(ms);
                      bmp[i] = bm;
  
                      ms.Close();
  
                  }
                  catch (Exception ex)
                  {
  
                  }
              }
  </code></pre>
  
  <p>ASpx.CS page:</p>
  
  <pre><code>Bitmap[] bm= photos.GetImage();
      for (int i = 0; i &lt; bm.Length; i++)
      {
    MemoryStream ms = new MemoryStream();
  
          **bm[i].Save(ms, ImageFormat.Jpeg);**(Error : A generic error occurred in GDI+.)
  
  htmlCode.Append("&lt;li&gt;&lt;img ImageUrl=\\\"");
  htmlCode.Append(**ms.GetBuffer()**);
  htmlCode.Append("\" alt=\"\" width=\"100\" height=\"100\"&gt;&lt;/li&gt;");
  }
  </code></pre>
  
  <p>Image not getting displayed</p>
  
  <p>Geetha</p>