Look at your error message:
value cannot be null. parameter name encoder
Now look at your code:
cmd = new SqlCommand("insert into Cafe_prodect (name_prodect,price,NO_Table,image_prodect,type_prodect)...
YOu do not set a value for the
encoder
column - and the error is saying that the table definition does not allow NULL values for that column.
Either provide a value, or change your table definition.
BTW: You do realise that you go all round the houses to get the job done?
Why not just do this:
string strInsert = "INSERT INTO Cafe_prodect " +
"(name_prodect, price, NO_Table, image_prodect, type_prodect) VALUES " +
"(@name_prodect, @price, @NO_Table, @image_prodect, @type_prodect)";
using (cmd = new SqlCommand(strInsert, cn))
{
MemoryStream ms = new MemoryStream();
pictureBox2.Image.Save(ms, pictureBox2.Image.RawFormat);
byte[] byteImage = ms.ToArray();
cmd.Parameters.AddWithValue("@name_prodect", txtPname.Text);
cmd.Parameters.AddWithValue("@price", txtPprice.Text);
cmd.Parameters.AddWithValue("@NO_Table", txtNoTbl.Text);
cmd.Parameters.AddWithValue("@image_prodect", byteImage);
cmd.Parameters.AddWithValue("@type_prodect", txtTyp.Text);
cmd.ExecuteNonQuery();
}