System.Data Namespace DataTable Class
Returns the collection of rows that belong to this table.
Script |
[ DataRowCollection variable = ] DataTable.Rows |
The property is read only with no default value.
To create a new DataRow, you must use the NewRow method to return a new object. Such an object is automatically configured with according to the schema defined for the DataTable through its collection of DataColumn objects. After creating a new row and setting the values for each column in the row, add the row to the DataRowCollection using the Add method.
Each DataRow in the collection represents a row of data in the table. To commit a change to the value of a column in the row, you must invoke the AcceptChanges method.
NOTE: DataTable.Rows returns a null value if no DataRow objects exist in the table.
The following examples demonstrate using the Rows property to print the values of each column in each row of a table.
Private void RowsDemo ( DataTable myTable ) {
foreach ( DataRow myRow in myTable.Rows ) {
foreach ( DataColumn myCol in myTable.Columns ) {
Response.Write ( myRow [ myCol ] );
}
}
}
Private Sub RowsDemo ( 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 DataRowCollection DataRow