System.Data.Common Namespace DataColumnMappingCollection Class
Sets or retrieves the specified DataColumnMapping from the collection.
1. Sets or retrieves the DataColumnMapping at the specified index.
2. Sets or retrieves the DataColumnMapping with the specified source column name.
The following example searches for a DataColumnMapping object with the given source column name within a DataColumnMappingCollection. If the DataColumnMapping exists, the code displays the name and index of the mapping; otherwise, it displays an error.
NOTE: This example uses one of the overloaded versions of the Item property ( DataColumnMappingCollection indexer ). For other examples that may be available, see the individual overload topics.
public void FindDataColumnMapping ( DataTableMapping myTableMap ) {
// get column mappings
DataColumnMappingCollection myFieldsMaps = myTableMap.ColumnMappings;
if ( myFieldsMaps.Contains ( "Description" ) ) {
MessageBox.Show ( "Name: " + myFieldsMaps [ "Description" ].ToString ( )
+ "\nIndex: " + myFieldsMaps.IndexOf ( "Description" ).ToString ( ) );
} else {
MessageBox.Show ( "Error: no such field in collection" );
}
}
Public Sub FindDataColumnMapping ( ByVal myTableMap As DataTableMapping )
' get column mappings
Dim myFieldsMaps As DataColumnMappingCollection = myTableMap.ColumnMappings;
If myFieldsMaps.Contains ( "Description" ) Then
MessageBox.Show ( "Name: " + myFieldsMaps ( "Description" ).ToString ( ) _
+ ControlChars.Cr + "Index: " + myFieldsMaps.IndexOf ( "Description" ).ToString ( ) )
Else
MessageBox.Show ( "Error: no such field in collection" )
End If
End Sub |
|
C# |
VB |
DataColumnMappingCollection Members