SqlBulkCopyColumnMappingCollection::Clear Method ()

 

Clears the contents of the collection.

Namespace:   System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public:
void Clear()

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.

System_CAPS_importantImportant

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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: