LINQ进行插入操作,但是总提示主键重复!
总提示我如下的语句:
Violation of PRIMARY KEY constraint 'PK_customer_accounter'. Cannot insert duplicate key in object 'dbo.customer_accounter'.
The statement has been terminated
程序也总停在linq.SubmitChanges();位置上。
原代码如下:
linq = new linqtosqlClassDataContext(strCon);
customer_accounter cusacc = new customer_accounter();
cusacc.Name = textBox_AddName.Text;
cusacc.Code = Convert.ToString(textBox_AddCode.Text);
cusacc.Authority = comboBoxEx.Text;
linq.customer_accounter.InsertOnSubmit(cusacc);
linq.SubmitChanges();
是不是数据库的设置有问题?表中一共有4个量,ID号(设为主键),账号,密码,用户权限.
编程环境VS2008,数据库SQL Server2005.
本人才接触数据库和LINQ,还请高人指点,谢谢!
------解决方案-------------------- 把主键设置为自增试试
------解决方案-------------------- 探讨 总提示我如下的语句: Violation of PRIMARY KEY constraint 'PK_customer_accounter'. Cannot insert duplicate key in object 'dbo.customer_accounter'. The statement has been terminated 程序也总停在linq.SubmitChange……
------解决方案-------------------- 1、主键是否自增或者GUID
2、是否多次插入