SqlBulkCopyColumnMappingCollection::Add Method (Int32, String^)
Creates a new SqlBulkCopyColumnMapping and adds it to the collection, using an ordinal for the source column and a string for the destination column.
Assembly: System.Data (in System.Data.dll)
Parameters
- sourceColumnIndex
-
Type:
System::Int32
The ordinal position of the source column within the data source.
- destinationColumn
-
Type:
System::String^
The name of the destination column within the destination table.
Mappings in a collection must be uniform: either all integer/integer pairs, all string/string pairs, all integer/string pairs, or all string/integer pairs. If you try to add a mapping that is different from others already in the collection, an InvalidOperationException is thrown.
The following example bulk copies data from a source table in the AdventureWorks sample database to a destination table in the same database. Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. SqlBulkCopyColumnMapping objects are used to create a column map for the bulk copy.
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
