System.Data Namespace DataColumnCollection Class
Returns the index of a DataColumn with the specified name.
[ VB ]
Overloads Public Function IndexOf ( _
ByVal columnName As String _
) As Integer
[ C# ]
public int IndexOf (
String columnName
);
[ C++ ]
public: int IndexOf (
String* columnName
);
[ JScript ]
public function IndexOf (
columnName : String
) : int
- columnName
- The name of the DataColumn to find.
The index of the DataColumn if it is in the collection; otherwise, -1.
Use the IndexOf method to determine the index of a given column.
Before calling IndexOf, you can test for the existence of a column by using the Contains method.
The following example returns the index of a named column in a DataColumnCollection.
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 DataColumnCollection.IndexOf Overload List Contains