sql自增列无法插入重复主键,求分析帮助
vs写c#程序时,用到数据库,报错显示ViolationofPRIMARYKEYconstraint'PK_Tables1'.Cannotinsertduplicatek...
vs写c#程序时,用到数据库,报错显示Violation of PRIMARY KEY constraint 'PK_Tables1'. Cannot insert duplicate key in object 'dbo.Tables1'. The duplicate key value is (0).
代码如下:string sql = String.Format("INSERT INTO Tables1(Names,Prices,Classfies)VALUES('0','1','2')",nam ,pric,classfi ); using (SqlConnection conn=new SqlConnection (connstring )) { conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); int n = comm.ExecuteNonQuery();
该代码最后一行时报错表格如下 展开
代码如下:string sql = String.Format("INSERT INTO Tables1(Names,Prices,Classfies)VALUES('0','1','2')",nam ,pric,classfi ); using (SqlConnection conn=new SqlConnection (connstring )) { conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); int n = comm.ExecuteNonQuery();
该代码最后一行时报错表格如下 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询