Gets the collection of rows that belong to this table.
[Visual Basic] Public ReadOnly Property Rows As RowsCollection [C#] public RowsCollection Rows {get;} [C++] public: __property RowsCollection* get_Rows(); [JScript] public function get Rows() : RowsCollection;
A RowsCollection that contains DataRow objects.
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 RowsCollection 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.
The following shows two examples of returning and setting rows. The first example uses the the Rows property and prints the value of each column for every row. The second example uses the DataTable object's NewRow method to create a new DataRow object with the schema of the DataTable. After setting the row values, the row is added to the RowsCollection through the Add method.
[Visual Basic]
Private Sub GetRows(ds As DataSet) Dim myRows As RowsCollection Dim t As DataTable Dim r As DataRow Dim c As DataColumn ' For each table in the DataSet, print the values of each row. For Each t In ds.Tables ' For each row, print the values of each column. For Each r In t.Rows For Each c in t.Columns Console.WriteLine(r(c)) Next Next Next End Sub Private Sub AddARow(ds As DataSet) Dim t As DataTable t = ds.Tables("Suppliers) ' Use the NewRow method to create a DataRow with the table's schema. Dim newRow As DataRow newRow = t.NewRow ' Set values in the columns: newRow("CompanyID") = "NewCompanyID" newRow("CompanyName") = "NewCompanyName" ' Add the row to the rows collection. t.Rows.Add(newRow) End Sub
DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | DataRow | RowsCollection | NewRow