2

ERROR [HY000] [MySQL][ODBC5.3(a) Driver][mysqlId-5.7.11] Column 'Images' cannot be null. (This is my Problem)

This is my inserting button code

OdbcConnection connection = new OdbcConnection("dsn=dsn_pos");
        MessageBox.Show(this.imagePath.Text);
        FileStream filestreme = new FileStream(imagePath.Text,System.IO.FileMode.Open,System.IO.FileAccess.Read);
        byte[] image = new byte[filestreme.Length];
        filestreme.Read(image, 0, Convert.ToInt32(filestreme.Length));
        filestreme.Close();




        connection.Open();
        string query = "INSERT INTO item_inventory (Images) VALUES (?)";
        OdbcCommand cmd = new OdbcCommand(query, connection);
        OdbcParameter prm = new OdbcParameter("@IMG",OdbcType.Binary,image.Length,ParameterDirection.Input,false,0,0,null,DataRowVersion.Current,image);
        cmd.Parameters.Add(prm);
        cmd.ExecuteNonQuery();
        connection.Close();

This one is my loading button code

 OpenFileDialog dialog = new OpenFileDialog();
        dialog.Filter = "png files(*.png)|*.png|jpg files(*.jpg)|*.jpg|All files(*.*)|*.*";
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            string picPath = dialog.FileName.ToString();
            imagePath.Text = picPath;
            pictureBox2.ImageLocation = picPath;
        }
Sir George
  • 37
  • 7

2 Answers2

0

The mysql driver works otherwise, it doesn't support named parameters, only orderd. You need to change your @IMG in query to ?. Afret that you query should be looks like:

INSERT INTO item_inventory (Images) VALUES (?)
0

this is the answer string query = "INSERT INTO item_inventory (Images) VALUES (?)";

Sir George
  • 37
  • 7