使用 linq 插入数据时出现此错误。在这个我有一个表,它有两列,一列是标识列,另一列是可为空的选框 txt。请提供解决方案。我的代码在这里。
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Marquee existing = context.Marquees.FirstOrDefault();
if (existing != null)
{
existing.marquee1 = txtMarquee.Text;
context.SubmitChanges();
lblmsg.Text = "Data Saved Successfully";
generalFunction.goGreen(lblmsg);
}
else
{
Marquee newMarquee = new Marquee();
newMarquee.marquee1 = txtMarquee.Text;
context.Marquees.InsertOnSubmit(existing);
context.SubmitChanges();
lblmsg.Text = "Data Saved Successfully";
generalFunction.goGreen(lblmsg);
}
}
catch (Exception ee)
{
lblmsg.Text = "Error: " + ee.Message;
}
}