Home All Groups Group Topic Archive Search About

Bulkcopy ignoring Primary keys exception

Author
5 Feb 2007 4:00 PM
arnoled
I want to make a bulkcopy (or insertcommand if this can't be
acomplished with bulk copy) to a table. But if there are rows that
are
already in the table, just ignore them (don't do the insert on that
row) , so it doesn't raise an exception of Violation of Primary Key.

I don't want to bring the whole table from de the database, that
would
be very low performant.


If you know any option to do these directly form .net it would be
great, any suggestion is welcome


thanks

(sorry for my english)

Author
5 Feb 2007 6:35 PM
Paul Clement
On 5 Feb 2007 08:00:56 -0800, "arnoled" <abdala.ferna***@gmail.com> wrote:

¤ I want to make a bulkcopy (or insertcommand if this can't be
¤ acomplished with bulk copy) to a table. But if there are rows that
¤ are
¤ already in the table, just ignore them (don't do the insert on that
¤ row) , so it doesn't raise an exception of Violation of Primary Key.
¤
¤ I don't want to bring the whole table from de the database, that
¤ would
¤ be very low performant.
¤
¤
¤ If you know any option to do these directly form .net it would be
¤ great, any suggestion is welcome

SQLBulkCopy is not a selective process. You should only bring in those rows to the DataAdapter or
DataReader that you want copied to the table. This can be accomplished in your SQL statement using
the NOT IN clause with a subquery:

http://msdn2.microsoft.com/en-US/library/ms177682.aspx


Paul
~~~~
Microsoft MVP (Visual Basic)

AddThis Social Bookmark Button