System.Data Namespace
Represents a collection of columns for a DataTable.
The DataColumnCollection defines the schema of a DataTable, and determines what kind of data each DataColumn can contain. This collection is accessed via the DataTable.Columns property.
Like most data collections in ADO.NET, the DataColumnCollection uses standard collection methods to manage the items in the collection. These include the methods Add, Clear, and Remove.
The collection also includes a Count property to determine how many DataColumn objects are in the collection, and a Contains method to verify whether a specified column index or name exists in the collection.
The following examples demonstrate using the Columns property to print the values of each column in each row of a table.
Private void ColumnsDemo ( DataTable myTable ) {
foreach ( DataRow myRow in myTable.Rows ) {
foreach ( DataColumn myCol in myTable.Columns ) {
Response.Write ( myRow [ myCol ] );
}
}
}
Private Sub ColumnsDemo ( ByVal myTable As DataTable )
Dim myRow As DataRow, myColumn As DataColumn
For Each myRow in myTable.Rows
For Each myColumn In myTable.Columns
Response.Write ( myRow ( myColumn ) )
Next
Next
End Sub |
|
C# |
VB |
Columns DataColumn DataTable DataRelation DataRow DataSet