asp.net.ph

DataColumnCollection.Item Property ( Int32 )

System.Data Namespace   DataColumnCollection Class


Returns the DataColumn at the specified index in the collection.

Syntax


DataColumn variable = DataColumnCollection.Item [ index ];
... or ...
DataColumn variable = DataColumnCollection [ index ];
  C# VB JScript

Parameters

index
The zero-based index of the column to return.

Property Value

The DataColumn at the specified index.

Exceptions


Exception Type Condition
IndexOutOfRangeException Occurs when the collection does not have a column at this index.

Remarks

The Contains method can be used to test for the existence of a column, which is useful before attempting to use the Item property.

Example

The following example uses the Item property to print the ColumnName values of all DataColumn objects in the collection, each specified by index.

private void PrintColumnNamesByIndex ( DataTable dt ) {
    // get the DataColumnCollection from a DataTable in a DataSet.
   DataColumnCollection cols = dt.Columns;
   // print each column's name using the index.
   for ( int ndx = 0; ndx < cols.Count; ndx++ ) {
      Response.Write ( cols [ ndx ] );
   }
}
  C# VB

See Also

DataColumnCollection Members   DataColumnCollection.Item Overload List   ColumnName   Contains   DataColumn 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