我开发了一个保存图片的程序。但我收到此错误信息:C#错误消息:无法将值NULL插入到列'Id
无法将NULL值插入列“ID”
private void savepicture()
{
if(pictureBox1.Image != null)
{
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] a = ms.GetBuffer();
ms.Close();
cm.Parameters.Clear();
cm.Parameters.AddWithValue("@picture", a);
cm.CommandText = "insert into Bild (FileName,Datei) values ('" + label1.Text.ToString() + "',@picture)";
sc.Open();
cm.ExecuteNonQuery(); // i get here the error message
sc.Close();
label1.Text = "";
pictureBox1.Image = null;
MessageBox.Show("Bild wurde gespeichert !");
}
}
什么是表的结构的方式插入标识?你有名为'id'的列有一个约束,它不能为空,但你不给它赋值... –
我猜ID应该被定义为数据库中的标识列。你需要告诉我们更多关于你的DBMS和'Bild'表。 –
你确定你在表中设置了“ID”作为主键吗? – Maher