System.Data.Common Namespace DataTableMappingCollection Class
Returns the index of a DataTableMapping with the specified SourceTable name.
[ VB ]
NotOverridable Overloads Public Function IndexOf ( _
ByVal sourceTable As String _
) As Integer Implements ITableMappingCollection.IndexOf
[ C# ]
public int IndexOf (
String sourceTable
);
[ C++ ]
public: __sealed int IndexOf (
String* sourceTable
);
[ JScript ]
public function IndexOf (
sourceTable : String
) : int
- sourceTable
- The case-sensitive name of a SourceTable.
The index of the DataTableMapping if it is in the collection; otherwise, -1.
ITableMappingCollection.IndexOf
Use the IndexOf method to determine the index of a given table mapping object.
Before calling IndexOf, you can test for the existence of a table mapping by using the Contains method.
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.
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 DataTableMappingCollection.IndexOf Overload List Contains