My DBML Designer Code is this
[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 this
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 am inserting data in text box error come Cannot insert explicit value for identity column in table 'userlogins' when IDENTITY_INSERT is set to OFF
Most likely your id
field is autogenerated in DB, while it is not mark as such in code. Add the following property to the Column
attribute:
IsDbGenerated=true
Or, if you are using visual editor for you LINQ model, mark this property as Auto Generated
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With