System.Data Namespace DataTableCollection Class
Returns the index of a DataTable with the specified name.
[ VB ]
Overloads Overridable Public Function IndexOf ( _
ByVal tableName As String _
) As Integer
[ C# ]
public virtual int IndexOf (
String tableName
);
[ C++ ]
public: virtual int IndexOf (
String* tableName
);
[ JScript ]
public function IndexOf (
tableName : String
) : int
- tableName
- The name of the DataTable to find.
The index of the DataTable if it is in the collection; otherwise, -1.
Use the IndexOf method to determine the index of a given table.
Before calling IndexOf, you can test for the existence of a table by using the Contains method.
The following example returns the index of a named table in a DataTableCollection.
private void GetIndexes ( DataSet ds ) {
DataTableCollection myTables = ds.Tables;
// get the index of the table named "Authors", if it exists.
if ( myTables.Contains ( "Authors" ) ) {
Response.Write ( myTables.IndexOf ( "Authors" ) );
}
}
Private Sub GetIndexes ( ByVal ds As DataSet )
Dim myTables As DataTableCollection = ds.Tables
' get the index of the table named "Authors", if it exists.
If myTables.Contains ( "Authors" ) Then
Response.Write ( myTables.IndexOf ( "Authors" ) )
End If
End Sub |
|
C# |
VB |
DataTableCollection Members DataTableCollection.IndexOf Overload List Contains