title: Saving and retrieving of images from SQL Server database using c#
body: <p>I have created a web page where I have used <code>Image</code> control to display the image. Along with this control I have some labels and input box also</p>
  
  <p>Below is the code which I have used to save the image to database</p>
  
  <pre><code>byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];
  HttpPostedFile uploadedImage = FileUpload1.PostedFile;
  uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
  
  SqlParameter UploadedImage = new SqlParameter("@image", SqlDbType.Image, imageSize.Length);
  UploadedImage.Value = imageSize;
  
  string sql = "insert into imageDB(Image) values (@image)";
  
  using (SqlCommand cmd = new SqlCommand(sql, conn))
  {
     cmd.Parameters.Add(UploadedImage);
     cmd.ExecuteNonQuery();
  }
  </code></pre>
  
  <p>and below is the code I have used to retrieve the image from database</p>
  
  <pre><code>byte[] rawImg = (byte[])rdr["image"];
  MemoryStream Stream = new MemoryStream();
  Stream.Write(rawImg, 0, rawImg.Length);
  Bitmap Display_Picture = new Bitmap(Stream);
  //after this no idea how to proceed
  </code></pre>
  
  <p>I have read some links all are suggesting we can not set this byte information to <code>Image</code> control.</p>
  
  <p>Let me know if my way of retrieving the image from data base is right, if its right, what type of control I should use, so that image which has been retrieved from database can be displayed on web page</p>