System.Data.Common Namespace DataTableMappingCollection Class
Sets or retrieves the specified DataTableMapping from the collection.
1. Sets or retrieves the DataTableMapping at the specified index.
2. Sets or retrieves the DataTableMapping with the specified source table name.
The following example searches for a DataTableMapping object with the given source table name within a DataTableMappingCollection. If the DataTableMapping 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 ( DataTableMappingCollection indexer ). For other examples that may be available, see the individual overload topics.
public void FindDataTableMapping ( DataAdapter myAdapter ) {
// get table mappings
DataTableMappingCollection myTables = myAdapter.TableMappings;
if ( myTables.Contains ( "Employees" ) ) {
MessageBox.Show ( "Name: " + myTables [ "Employees" ].ToString ( )
+ "\nIndex: " + myTables.IndexOf ( "Employees" ).ToString ( ) );
} else {
MessageBox.Show ( "Error: no such table in collection" );
}
}
Public Sub FindDataTableMapping ( ByVal myAdapter As DataAdapter )
' get table mappings
Dim myTables As DataTableMappingCollection = myAdapter.TableMappings;
If myTables.Contains ( "Employees" ) Then
MessageBox.Show ( "Name: " + myTables ( "Employees" ).ToString ( ) _
+ ControlChars.Cr + "Index: " + myTables.IndexOf ( "Employees" ).ToString ( ) )
Else
MessageBox.Show ( "Error: no such table in collection" )
End If
End Sub |
|
C# |
VB |
DataTableMappingCollection Members