Cannot insert explicit value for identity column in userlogins table if IDENTITY_INSERT is set to OFF?

My DBML constructor code is

[Column(Storage="_id",IsPrimaryKey=true,DbType="Int")] public System.Nullable<int> id { get { return this._id; } set { if ((this._id != value)) { this._id = value; } } } 

and My C # Code is

 DataClassesDataContext db = new DataClassesDataContext(); userlogin tc = new userlogin(); tc.username = TextBox1.Text; tc.pass = TextBox2.Text; db.userlogins.InsertOnSubmit(tc); db.SubmitChanges(); Response.Redirect("Main.aspx"); 

when I insert data into a text box, errors come in. It is not possible to insert an explicit value for the identity column in the userlogins table if the IDENTITY_INSERT parameter is set to OFF

+4
source share
1 answer

Most likely, your id field is autogenerated in the database, while it is not as such in the code. Add the following property to the Column attribute:

 IsDbGenerated=true 

Or, if you are using a visual editor for your LINQ model, mark this property as Auto Generated .

+8
source

Source: https://habr.com/ru/post/1487265/


All Articles