I am trying to insert an image to access database through my C# application. But every time I am getting exception
private void button1_Click(object sender, EventArgs e)
{
try
{
connection.Open();
string str = "INSERT INTO imageInsertRetrieve (FirstName,LastName,Image) values ('" + textBox1.Text + "','" + textBox2.Text + "',(@img))";
cmd = new OleDbCommand(str, connection);
ms = new MemoryStream();
pictureBox1.Image.Save(ms, ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd.Parameters.AddWithValue("@img", photo_aray);
cmd.ExecuteNonQuery();
}
catch(Exception exp)
{
MessageBox.Show(exp.ToString());
}
finally
{
connection.Close();
}
}