SqlBulkCopy import causes primary key violations in SQL Server

c# sqlbulkcopy sql-server

Question

In C#.NET, I'm attempting to create a window-based application. I'm reading data from a csv file into a data grid view before inserting it into a database. I useSqlBulkCopy to database to insert data from csv file. My main worry is that I keep receiving primary key constraint errors when I attempt to put data into databases that already contain data. If it's feasible to compare values before putting them into a database utilizingSqlBulkCopy Update should occur if the value is present in the database.

Can someone explain the rationale behind this?

Thanks.

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

Popular Answer

Set the "Ignore Dupes" option on the index for the PK if you are absolutely certain that the dupes are not required.

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