views:

491

answers:

2

Hi,

I have a datatable with the records.I'm inserting records into Sql table using SqlBulkCopy.It works fine.Next time when get the datatable with same records with few changed values SqlBulkCopy is inserting another set of records without updating the previous details.How can I update the Sql table using SqlBulkCopy ?? Please help.

Thanks, Vix

+3  A: 

Hi,

SqlBulkCopy is only used for inserting records, not updating them as explained here. You'd need to use a different technique to do bulk updates.

e.g. you could SqlBulkCopy into a staging table, then run some SQL to update from there to the main table.

AdaTheDev
+1 for staging table, that's exactly how you must do updates with bulk-insert, and for massive amounts of updates on the same tables, it's well worth the effort to do it.
Lasse V. Karlsen
+2  A: 

Hi Vinod, Truncate the table and perform Bulkcopy.

krishna kishore aluri
for vix: Truncate then bulk load is the most efficient process if you only want the resulting table to contain only the bulk load records. - upvoted
Chad