asp.net.ph

DataTable.Rows Property

System.Data Namespace   DataTable Class


Returns the collection of rows that belong to this table.

Syntax


Script [ DataRowCollection variable = ] DataTable.Rows

Property Value


variable Returns the DataRowCollection that contains the DataRow objects for the table.

The property is read only with no default value.

Remarks

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.

Example

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 ] );
      }
    }
}
  C# VB

Retrieving OleDb Data into a DataSet
Run Sample | View Source
Retrieving SQL Data into a DataSet
Run Sample | View Source
Retrieving XML Data into a DataSet
Run Sample | View Source

See Also

DataTable Members   DataRowCollection   DataRow Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

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

You can help support asp.net.ph