Ankush

Ankush

  • NA
  • 267
  • 62.9k

Retrieve Image from Sql Database using c#

Apr 6 2016 2:25 PM
I am developing a windows application using c#, where the user will save the image and retrieve the image. The image saving is working, but retrieving the image from database to picture box is not working. The code I have written was working 2 days back, but now its not working, Error occurs at runtime as "Parameter is not valid" @ line no.10 Here is my code below :-
  1. string cnstd = ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString;  
  2. SqlConnection cone = new SqlConnection(cnstd);  
  3. cone.Open();  
  4. string sql = "Select Pic from Emp_Details";  
  5. SqlCommand command = new SqlCommand(sql, cone);  
  6. byte[] image = (byte[])command.ExecuteScalar();  
  7. cone.Close();  
  8. MemoryStream ms = new MemoryStream(image);  
  9. ms.Seek(0, SeekOrigin.Begin);  
  10. bitmap = (Bitmap)System.Drawing.Image.FromStream(ms);  
  11. pbLogo.Image = bitmap;  
Thanks in Advance !!!

Answers (3)