Cannot insert explicit value for identity column in table 'IncomeTable' when IDENTITY_INSERT is set to OFF
12,904
Solution 1
You can try this:
- Open your table in visual designer
- Click your column - Properties
- Set
Auto Generated Value = True
- Set
Auto Sync = True
- Check the data type for that column if it's
Int NOT NULL IDENTITY
Solution 2
One of these columns:
income.amount_income = amount;
income.comment_income = comment;
income.date_income = date;
is an identity column in the database. Check your table definitions and remove it.
Author by
Nice NICE
Updated on June 05, 2022Comments
-
Nice NICE almost 2 years
I set status of primary key in table to IDENTITY . I insert another fields of table in VS but when i run this program, the program has error. Why? What is my problem?
ID field in my table is set Identity.
The runtime error is:
Cannot insert explicit value for identity column in table 'IncomeTable' when IDENTITY_INSERT is set to OFF.
in 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(); }
I search but i cant solve this problem. Cheers