I want to inserted new row in database using linq to sql
I tried to add new items in items table in database using linq to sql like this :
Items new_item = new Items();
new_item.Title = editproductid.Text;
new_item.Path = @"~\images\" + uploadimage.开发者_开发技巧FileName;
StaticVa.new_data_context.Items.InsertOnSubmit(new_item);
StaticVa.new_data_context.SubmitChanges();
but I got an exception
Cannot insert explicit value for identity column in table 'Items' when IDENTITY_INSERT is set to OFF.
how can I open it ? or are there another ways to insert ?
You need to make sure that the "Auto Generate Value" property in your model for the identity column is set to True, so that Linq to Sql knows to not try to insert a value itself.
精彩评论