Export (0) Print
Expand All

SqlBulkCopyColumnMappingCollection Class

Collection of SqlBulkCopyColumnMapping objects that inherits from CollectionBase.

System::Object
  System.Collections::CollectionBase
    System.Data.SqlClient::SqlBulkCopyColumnMappingCollection

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

public ref class SqlBulkCopyColumnMappingCollection sealed : public CollectionBase

The SqlBulkCopyColumnMappingCollection type exposes the following members.

  NameDescription
Public propertyCapacityGets or sets the number of elements that the CollectionBase can contain. (Inherited from CollectionBase.)
Public propertyCountGets the number of elements contained in the CollectionBase instance. This property cannot be overridden. (Inherited from CollectionBase.)
Public propertyItemGets the SqlBulkCopyColumnMapping object at the specified index.
Top

  NameDescription
Public methodAdd(SqlBulkCopyColumnMapping)Adds the specified mapping to the SqlBulkCopyColumnMappingCollection.
Public methodAdd(Int32, Int32)Creates a new SqlBulkCopyColumnMapping and adds it to the collection, using ordinals to specify both source and destination columns.
Public methodAdd(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.
Public methodAdd(String, Int32)Creates a new SqlBulkCopyColumnMapping and adds it to the collection, using a column name to describe the source column and an ordinal to specify the destination column.
Public methodAdd(String, String)Creates a new SqlBulkCopyColumnMapping and adds it to the collection, using column names to specify both source and destination columns.
Public methodClearClears the contents of the collection.
Public methodContainsGets a value indicating whether a specified SqlBulkCopyColumnMapping object exists in the collection.
Public methodCopyToCopies the elements of the SqlBulkCopyColumnMappingCollection to an array of SqlBulkCopyColumnMapping items, starting at a particular index.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator that iterates through the CollectionBase instance. (Inherited from CollectionBase.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfGets the index of the specified SqlBulkCopyColumnMapping object.
Public methodInsertInsert a new SqlBulkCopyColumnMapping at the index specified.
Public methodRemoveRemoves the specified SqlBulkCopyColumnMapping element from the SqlBulkCopyColumnMappingCollection.
Public methodRemoveAtRemoves the mapping at the specified index from the collection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection::CopyToCopies the entire CollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate propertyICollection::IsSynchronizedGets a value indicating whether access to the CollectionBase is synchronized (thread safe). (Inherited from CollectionBase.)
Explicit interface implemetationPrivate propertyICollection::SyncRootGets an object that can be used to synchronize access to the CollectionBase. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate methodIList::AddAdds an object to the end of the CollectionBase. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate methodIList::ContainsDetermines whether the CollectionBase contains a specific element. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate methodIList::IndexOfSearches for the specified Object and returns the zero-based index of the first occurrence within the entire CollectionBase. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate methodIList::InsertInserts an element into the CollectionBase at the specified index. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate propertyIList::IsFixedSizeGets a value indicating whether the CollectionBase has a fixed size. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate propertyIList::IsReadOnlyGets a value indicating whether the CollectionBase is read-only. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate propertyIList::ItemGets or sets the element at the specified index. (Inherited from CollectionBase.)
Explicit interface implemetationPrivate methodIList::RemoveRemoves the first occurrence of a specific object from the CollectionBase. (Inherited from CollectionBase.)
Top

Column mappings define the mapping between data source and the target table.

If mappings are not defined—that is, the ColumnMappings collection is empty—the columns are mapped implicitly based on ordinal position. For this to work, source and target schemas must match. If they do not, an InvalidOperationException is thrown.

If the ColumnMappings collection is not empty, not every column present in the data source has to be specified. Those not mapped by the collection are ignored.

You can refer to source and target columns by either name or ordinal. You can mix by-name and by-ordinal column references in the same mappings collection.

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 are added to the SqlBulkCopyColumnMappingCollection for the SqlBulkCopy object to create a column map for the bulk copy.

Important noteImportant

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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft