SqlBulkCopyColumnMappingCollection::Remove Method (SqlBulkCopyColumnMapping^)

 

Removes the specified SqlBulkCopyColumnMapping element from the SqlBulkCopyColumnMappingCollection.

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

public:
void Remove(
	SqlBulkCopyColumnMapping^ value
)

Parameters

value
Type: System.Data.SqlClient::SqlBulkCopyColumnMapping^

SqlBulkCopyColumnMapping object to be removed from the collection.

The Remove 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 remove mappings that no longer apply after the WriteToServer method is called and before defining mapping for the next bulk copy. You can clear the entire collection by using the Clear method, or remove mappings individually using the Remove method or the RemoveAt method.

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. Both bulk copies include a mapping for the SalesOrderID, so rather than clearing the entire collection between bulk copy operations, the example removes all mappings except for the SalesOrderID mapping and then adds the appropriate mappings for the second bulk copy operation.

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: