System.Data Namespace DataColumnCollection Class
Returns the DataColumn at the specified index in the collection.
DataColumn variable = DataColumnCollection.Item [ index ];
... or ...
DataColumn variable = DataColumnCollection [ index ];
dim variable as DataColumn = DataColumnCollection.Item ( index )
... or ...
dim variable as DataColumn = DataColumnCollection ( index )
variable : DataColumn = DataColumnCollection.Item ( index );
... or ...
variable : DataColumn = DataColumnCollection ( index ); |
|
C# |
VB |
JScript |
- index
- The zero-based index of the column to return.
The DataColumn at the specified index.
The Contains method can be used to test for the existence of a column, which is useful before attempting to use the Item property.
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 ] );
}
}
Private Sub PrintColumnNamesByIndex ( Dim dt As DataTable )
' get the DataColumnCollection from a DataTable in a DataSet.
Dim cols As DataColumnCollection = dt.Columns
' print each column's name using the index.
For ndx = 0 To cols.Count -1
Response.Write ( cols ( ndx ) )
Next
End Sub |
|
C# |
VB |
DataColumnCollection Members DataColumnCollection.Item Overload List ColumnName Contains DataColumn