HELP.... Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to...


Author
Message
Ross L Rooker, Sr.(1)
Ross L Rooker, Sr.(1)
StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)
Group: StrataFrame Users
Posts: 50, Visits: 163
By default the table has an auto incrementing primary key. I need to be able to specify the primary key in the insert command. I checked the insert statement being sent to the backend and that insert statement looks good. I must be missing something. Why am I getting this error?

string strSQL = "set identity_insert tblIndividual ON ";
ExecuteNonQuery(strSQL);

this.PrimaryKeyIsAutoIncremented = false;
this.PrimaryKeyIsUpdatable = true;
               
this.Add();
this.Individual_First = "John";
this.Individual_Last = "Doe";
this.Individual_Key = 12345;      // Primary Key
this.Save();         ---------------> this line gets the error

-------------------------------------------------------------------------------------------------
DataLayerSavingException
  Cannot insert explicit value for identity column in table 'tblIndividual' when IDENTITY_INSERT is set to OFF.
SqlException
  Cannot insert explicit value for identity column in table 'tblIndividual' when IDENTITY_INSERT is set to OFF.

Source     : MicroFour StrataFrame Business
-------------------------------------------------------------------------------------------------




string strSQL = "set identity_insert tblIndividual OFF ";
ExecuteNonQuery(strSQL);

this.PrimaryKeyIsAutoIncremented = true;
this.PrimaryKeyIsUpdatable = false;
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search