System.Data Namespace DataTable Class
Returns the collection of columns that belong to this table.
Script |
[ DataColumnCollection variable = ] DataTable.Columns |
The property is read only with no default value.
The DataColumnCollection determines the schema of a table by defining the data type of each column.
NOTE: DataTable.Columns returns a null value if no DataColumn objects exist in the table.
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 |
DataTable Members DataColumnCollection DataColumn