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:

  1. Open your table in visual designer
  2. Click your column - Properties
  3. Set Auto Generated Value = True
  4. Set Auto Sync = True
  5. 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.

Share:
12,904
Nice NICE
Author by

Nice NICE

Updated on June 05, 2022

Comments

  • Nice NICE
    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