错误[HY000] [MySQL] [ODBC5.3(a) 驱动程序] [mysqlId-5.7.11]列'图像' 不能为空。(这是我的问题)
这是我的插入按钮代码
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();
这是我的加载按钮代码
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;
}
答案 0 :(得分:0)
mysql驱动程序另有工作,它不支持命名参数,只有orderd。您需要将查询中的@IMG更改为?。 您查询后应该看起来像:
INSERT INTO item_inventory (Images) VALUES (?)
答案 1 :(得分:0)
这是答案字符串查询=" INSERT INTO item_inventory(Images)VALUES(?)&#34 ;;