asp.net.ph

DataColumnCollection.IndexOf Method ( String )

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

Parameters

columnName
The name of the DataColumn to find.

Return Value

The index of the DataColumn if it is in the collection; otherwise, -1.

Remarks

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.

Example

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" ) );
   }
}
  C# VB

See Also

DataColumnCollection Members   DataColumnCollection.IndexOf Overload List   Contains Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph