PrimaryKey违规错误--- SP完美运行 [英] PrimaryKey Violation Error---SP is working Perfectly
问题描述
大家好,
我试图将XML数据插入到SQL表中.为此,我编写了 SP ,我的SP可以正常工作.我认为pblm在编码方面.
在执行代码时,我遇到了错误.完成此行后 dAdapter.Fill(dset); 语句未返回,它直接转到 Catch .然后出现这种错误
错误:
Hi everyone ,
I tried to insert XML data into my SQL Table.For that i wrote SP,my SP is perfectly working. I think pblm is in coding side.
At the time of executing the Code, i got error.After completion of this line dAdapter.Fill(dset); statement has not been return,it''s directly goes to Catch .Then i got this type of error
error:
Violation of PRIMARY KEY constraint 'PK_ESS_Discipline'. Cannot insert duplicate key in object 'dbo.EMS_M_Discipline'. The duplicate key value is (DIS000554).
The statement has been terminated.
但是在我的表中没有像"DIS000554"这样的记录
代码:
But in my Table There is no record like ''DIS000554''
Code:
public DataSet uploadToSqlTable(string xmlDoc)
{
DataSet dset;
SqlDataAdapter dAdapter;
SqlCommand command = new SqlCommand();
try
{
dAdapter = new SqlDataAdapter(spNameForXlUpload, con);
command.CommandType = CommandType.StoredProcedure;
command.Connection = con;
command.CommandText = spNameForXlUpload;
command.Parameters.Add(new SqlParameter("@XMLItemsDoc", xmlDoc.Trim()));
//command.Parameters.Add(new SqlParameter("@Disc_Code", Disc_Code));
dAdapter.SelectCommand = command;
dset = new DataSet();
dAdapter.Fill(dset);
return dset;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
谁能帮助我做到这一点.
预先表示感谢....
can anyone help me to do this.
Thank''s in advance....
推荐答案
Violation of PRIMARY KEY constraint 'PK_ESS_Discipline'. Cannot insert duplicate key in object 'dbo.EMS_M_Discipline'. The duplicate key value is (DIS000554).
The statement has been terminated.
错误消息很清楚.
您正在尝试为主键插入重复的值.检查表EMS_M_Discipline并查找表中是否已经存在您现在传递的主键.
The error message is very clear.
You are trying to insert duplicate value for the primary key..Check Your table EMS_M_Discipline and find whether what ever primary key you pass now is already there in table.
这篇关于PrimaryKey违规错误--- SP完美运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!