Paramu
Paramu

Reputation: 613

Primary Key Field Problem - Violation of Primary Key Constraint' PK_MyTable_179AOAFE03317E3D' Cannot Insert..?

I am using SQL Server 2008. When I save by First_Click of Save button its saving no problem. Suppose if I reclick the save button again I am getting the above error. So how to solve this type of problems?

I have a field primary key MyPrimField.

And I am getting the data using the following code:

DataTable ChkClone = MyDtb1.Clone();
DataRow[] MyCloneRow = MyDtb1.Select("door_no is not null");

foreach (DataRow DaR in MyCloneRow)
{
    ChkClone.ImportRow(DaR);
}

Upvotes: 0

Views: 242

Answers (1)

taylonr
taylonr

Reputation: 10790

It's been a while since I did ado.net, but from your code it looks like ChkClone is the same as MyDtb1 (since you're doing a clone.)

Then in your for loop, you're trying to import a row into the data table, but it already exists.

Upvotes: 1

Related Questions