我將表中主鍵的狀態設置爲IDENTITY。我在VS中插入另一個表的字段,但是當我運行這個程序時,程序有錯誤。爲什麼?我的問題是什麼?當IDENTITY_INSERT設置爲OFF時,無法在表'IncomeTable'中爲標識列插入顯式值
我的表中的ID字段被設置爲Identity。
運行時錯誤是:
Cannot insert explicit value for identity column in table 'IncomeTable' when IDENTITY_INSERT is set to OFF.
在VS
:
private void button1_Click(object sender, EventArgs e)
{
IncomeTable income = new IncomeTable();
income.amount_income = amount;
income.comment_income = comment;
income.date_income = date;
context.IncomeTables.InsertOnSubmit(income);
context.SubmitChanges();
}
我搜索,但我不能解決這個問題。 乾杯
你使用LINQ to SQL嗎? –
是的。我使用LINQ to SQL –