SqlBulkCopy.WriteToServer Method (DataTable, DataRowState)
Assembly: System.Data (in System.Data.dll)
Only rows in the DataTable that are in the states indicated in the rowState argument and have not been deleted are copied to the destination table.
While the bulk copy operation is in progress, the associated destination SqlConnection is busy serving it, and no other operations can be performed on the connection.
The following Console application demonstrates how to bulk load only the rows in a DataTable that match a specified state. In this case, only unchanged rows are added. The destination table is a table in the AdventureWorks database.
In this example, a DataTable is created at run time and three rows are added to it. Before the method is executed, one of the rows is edited. The method is called with a DataRowState.UnchangedrowState argument, so only the two unchanged rows are bulk copied to the destination.
This sample will not run unless you have created the work tables as described in Bulk Copy Example Setup. This code is provided to demonstrate the syntax for using SqlBulkCopy only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL INSERT … SELECT statement to copy the data.
Available since 2.0