i'm trying to retrieve my image from the database, as its stored as an array of bytes. and display in my picture control in winform. I'm currently getting an:
invalid operationunhandled excepetion. ExecuteScalar: Connection property has not been initialized.
byte[] imagearray = (byte[])cmd.ExecuteScalar();
here the rest of my code:
using (SqlConnection sql = new SqlConnection(@"data source=.\SQLEXPRESS;Integrated Security=SSPI;User Instance=true"))
{
SqlCommand cmd = new SqlCommand("SELECT Image FROM Items WHERE (Image = @image");
cmd.Parameters.Add("image", SqlDbType.Image);
cmd.Parameters[0].Value = textBox1.Text;
sql.Open();
byte[] imagearray = (byte[])cmd.ExecuteScalar();
MemoryStream ms = new MemoryStream(imagearray);
System.Drawing.Bitmap a = new System.Drawing.Bitmap(ms);
pictureBox1.Image = a;
}
so where am i going wrong? also a solution to this would be nice.
thanks in advance
ray

New Topic/Question
Reply



MultiQuote




|