System.Data Namespace DataColumnCollection Class
Returns the index of the specified DataColumn.
Returns the index of a specified DataColumn object.
Returns the index of a DataColumn with the specified name.
The following example returns the index of a named column in a DataColumnCollection.
NOTE: This example uses one of the overloaded versions of IndexOf. For other examples that may be available, see the individual overload topics.
private void GetIndexes ( DataTable myTable ) {
DataColumnCollection myCols = myTable.Columns;
// get the index of the column named "City", if it exists.
if ( myCols.Contains ( "City" ) ) {
Response.Write ( myCols.IndexOf ( "City" ) );
}
}
Private Sub GetIndexes ( ByVal myTable As DataTable )
Dim myCols As DataColumnCollection = myTable.Columns
' get the index of the column named "City", if it exists.
If myCols.Contains ( "City" ) Then
Response.Write ( myCols.IndexOf ( "City" ) )
End If
End Sub |
|
C# |
VB |
DataColumnCollection Members