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




Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

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