I am trying to use SqlBulkCopy to insert new rows into my DB table by manually populating a DataTable with my application.
This works great for all tables except a table with a composite primary key consisting of 3 columns . Whenever I try to execute SqlBulkCopy in this table, I get the following error:
Violation of PRIMARY KEY constraint 'PK_MYCOMPOSITEKEY'. Cannot insert duplicate key in object 'dbo.MyTable'.
The statement has been terminated.
Is it possible?
I tried setting up the primary keys of a DataTable with the following:
dt.PrimaryKey = new[] {dt.Columns["PKcolumn1"], dt.Columns["PKcolumn2"], dt.Columns["PKcolumn3"]};
but again, no luck.
source
share