Hello,
I have an application where I save an image to a database in a column of type VARBINARY(1024) I used 1024 because I think is the number of bytes and I want to handle images no larger than 1MB.
I have my code to save the image and it works.
The thing is that when I try to retrieve the image it tells me Parameter is invalid. I check in the debugger and it brings the byte[] array from the database so the problem is in the MemoryStream I have searched a lot but have not found an answer here is my code to retrieve the image:
string sKey = dgvCatalog.SelectedRows[0].Cells[0].Value.ToString();
byte[] bImage = new byte[0];
conn.Open();
cmd = new SqlCommand("SELECT description, picture FROM Books WHERE ISBN ='" + sKey + "';", conn);
dr = cmd.ExecuteReader();
dr.Read();
tbBookDescription.Text = dr[0].ToString();
bImage = (byte[])dr["picture"];
MemoryStream ms = new MemoryStream(bImage);
pbItemImage.Image = Image.FromStream(ms);
dr.Close();
conn.Close();
What am i doing wrong?
Thanks in advance.