SqlBulkCopy import causes primary key violations in SQL Server

c# sqlbulkcopy sql-server

Question

I am trying to design a window based application in C#.NET. I am reading csv file in data grid view and then insert those data into database. I am using SqlBulkCopy to insert data from csv file into database. My concern is, when I am trying to insert data into database (which already consist data) I am getting error of primary key constraint. I want to know whether it is possible to compare value before inserting into database using SqlBulkCopy. If value exist in database it should do update.

Can anyone provide me logic for this.

Thanks.

1
1
3/12/2011 10:47:07 PM

Popular Answer

If you really, really know that the dupes aren't needed, just set the "Ignore Dupes" option on the index for the PK and you're done.

2
3/13/2011 6:32:11 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow