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 :-
- string cnstd = ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString;
- SqlConnection cone = new SqlConnection(cnstd);
- cone.Open();
- string sql = "Select Pic from Emp_Details";
- SqlCommand command = new SqlCommand(sql, cone);
- byte[] image = (byte[])command.ExecuteScalar();
- cone.Close();
- MemoryStream ms = new MemoryStream(image);
- ms.Seek(0, SeekOrigin.Begin);
- bitmap = (Bitmap)System.Drawing.Image.FromStream(ms);
- pbLogo.Image = bitmap;
Thanks in Advance !!!

Nishant MittalRank #692 · 3.5K reputationPosted Apr 6, 2016, 8:55 PM EDT
connection.Open(); SqlCommand command1 = new SqlCommand("select imgfile from myimages where imgname=@param", connection); SqlParameter myparam = command1.Parameters.Add("@param", SqlDbType.NVarChar, 30); myparam.Value = txtimgname.Text; byte[] img = (byte[])command1.ExecuteScalar(); MemoryStream str = new MemoryStream(); str.Write(img, 0, img.Length); Bitmap bit = new Bitmap(str); connection.Close();Vivek Bansod142 reputationPosted Apr 6, 2016, 9:08 PM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted May 1, 2016, 7:47 AM EDT