开发者

I want to inserted new row in database using linq to sql

开发者 https://www.devze.com 2023-04-05 22:10 出处:网络
I tried to add new items in items table in database using linq to sql like this : Items new_item = new Items();

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号