As I have made a table ‘[tblWatchDog]’ with columns ImageID (type int, identity type auto increment)and ImageData (type image). Images saved successfully. While retriving I got the Error “Parameter is not valid.”
Here is my code:
private void btnDisplay_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != null)
pictureBox1.Image.Dispose();
SqlConnection con = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand(@"SELECT ImageData FROM tblWatchDog WHERE ImageID=1", con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds, "tblWatchDog");
try
{
if (con.State == ConnectionState.Closed)
con.Open();
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0][0] != System.DBNull.Value)
{
byte[] photo_aray = (byte[])ds.Tables[0].Rows[0][0];
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
Image img = (Image)converter.ConvertFrom(photo_aray);
pictureBox1.Image = img;// Image.FromStream(mst);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Refresh();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
pl help !