I have one class called Functions which will store Insert, Update and Delete functions. The problem is that I cannot figure out how to pass the image(which I get from picturebox). Here's what I tried: Functions class:
public static Functions Insert(String u, String v, byte[] img)
{
String query = string.Format("INSERT INTO example(Name, Description) VALUES ('{0}', '{1}, {2}')", u, v,img);
MySqlCommand cmd = new MySqlCommand(query, dbConn);
dbConn.Open();
cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() == 1)
{
MessageBox.Show("Succesfully added!");
}
int id = (int)cmd.LastInsertedId;
Functions func = new Functions(id,u,v,img);
dbConn.Close();
return func;
}
Button in Form1:
private void button2_Click(object sender, EventArgs e)
{
String u = textBox2.Text;
String v = textBox3.Text;
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] img = ms.ToArray();
currf = Functions.Insert(u, v, img);
}
Here's the error message:
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Field 'Image' doesn't have a default value