SqlBulkCopyColumnMappingCollection::Clear Method ()
Clears the contents of the collection.
Assembly: System.Data (in System.Data.dll)
The Clear method is most commonly used when you use a single SqlBulkCopy instance to process more than one bulk copy operation. If you create column mappings for one bulk copy operation, you must clear the SqlBulkCopyColumnMappingCollection after the WriteToServer method and before processing the next bulk copy.
Performing several bulk copies using the same SqlBulkCopy instance will usually be more efficient from a performance point of view than using a separate SqlBulkCopy for each operation.
The following example performs two bulk copy operations. The first operation copies sales order header information, and the second copies sales order details. Although not strictly necessary in this example (because the ordinal positions of the source and destination columns do match), the example defines column mappings for each bulk copy operation. The Clear method must be used after the first bulk copy is performed and before the next bulk copy's column mappings are defined.
Important |
|---|
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
