sql-serversqlbulkcopy

SQLBulkCopy Row Count When Complete


I am using SQLBulkCopy to move large amounts of data. I implemented the notification event to notify me every time a certain number of rows have been processed, but the OnSqlRowsCopied event does not fire when the job is completed. How do I get the total number of rows copied when the SQLBulkCopy writetoserver completes?


Solution

  • I think you have to run a COUNT() query on the table after finishing, as in the MSDN example here.

    Other than that, can't you tell up front? e.g. if you're passing a DataTable to WriteToServer() then you know how many records by doing a .Rows.Count on it.