.NET Framework class library
DataTable.rows attribute
Get a collection of rows belonging to the table.
[Visual Basic]
Public Readonly Property Rows AS DatarowCollection
[C #]
Public DataRowcollection rows {get;}
[C ]
PUBLIC: __PROPERTY DATAROWCOLLECTION * GET_ROWS ();
[Jscript]
PUBLIC FUNCTION GET ROWS (): DATAROWCOLLECTION;
Attribute value
Contains DATAROWCOLLECTION of the DATAROW object; otherwise a null value (if there is no DataRow object).
Note
To create a new DataRow, you must return to a new object using the Newrow method. Such objects will be automatically configured according to the architecture, which is defined by the collection of DataColumn objects. After you create a new row and set the value for each column in the line, use the add method to add the row to the DataRowCollection.
Each DATAROW in the collection indicates a row of data in the table. To submit a change in the value of a column in the row, you must call the AcceptChanges method.
Example
[Visual Basic, C #, C ] The following shows an example of two returns and set rows. The first example uses the ROWS attribute and prints the value of each column for each row. The second example creates a new DataRow object with the architecture of the DataTable object using the Newrow method of the DataTable object. After setting the row value, add the row to the DataRowCollection via the Add method.
[Visual Basic]
Private sub printrows (MyDataSet AS Dataset)
'For Each Table in The DataSet, Print The Values of Each Row.
DIM THISTABLE AS DATATABLE
For Each THistable in MyDataSet.tables
'For Each Row, Print The Values of Each Column.
Dim Myrow As DataRow
For Each Myrow in thisTable.Rows
DIM Mycol as datacolumn
For Each Mycol in Thistable.columns
Console.WriteLine (MyRow)
Next mycol
Next Myrow
Next thisTable
End Sub
Private Sub Addarow (DS AS Dataset)
Dim t as dataatable
T = ds.tables ("suppliers")
'Use the newrow method to create a datarow with the table's schema.
DIM Newrow As DataRow = 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
[C #]
Private Void Printrows (Dataset MyDataSet) {// for Each Table in The Dataset, Print The Values of Each Row.
Foreach (DATATABLE THISTABLE IN MyDataSet.tables) {
// for Each Row, Print The VALUES OF Each Column.
Foreach (DataRow Myrow In Thistable.Rows) {
Foreach (Datacolumn mycol in thistable.column) {
Console.writeline (MyRow [mycol]);
}
}
}
}
Private Void Addarow (DataSet DS) {
DataTable T;
T = DS.TABLES ["support"];
// use the newrow method to create a datarow with the table's schema.
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);
}
[C ]
Private:
Void Printrows (Dataset * MyDataSet) {
// for Each Table in the Dataset, Print The Values of Each Row.
System :: Collections :: ienumerator * myenum = myDataSet-> TABLES-> getenumerator ();
While (MyEnum-> MoveNext ())
{
DataTable * thisTable = __TRY_CAST
// for Each Row, Print The VALUES OF Each Column.
System :: Collections :: ienumerator * myenum1 = thisTable-> rows-> getenumerator ();
While (MyEnum1-> MoveNext ())
{
DATAROW * Myrow = __TRY_CAST
System :: Collections :: ienumerator * myenum2 = thisTable-> columns-> getenumerator ();
While (MyEnum2-> MoveNext ())
{
Datacolumn * mycol = __TRY_CAST
Console :: WriteLine (MyRow-> item [mycol]);
}
}
}
}
Void Addarow (DataSet * DS) {
DataTable * T;
T = DS-> TABLES-> Item [S "Suppliers"];
// use the newrow method to create a datarow with the table's schema.datarow * newrow = t-> newrow ();
// SET VALUES in the columns:
NEWROW-> item [s "companyid"] = s "newcompanyid";
NEWROW-> Item [s "CompanyName"] = s "newcompanyname";
// add the row to the rows collection.
T-> rows-> add (newrow);
}
[JScript] There is no example available for JScript. To view Visual Basic, C # or C examples, click the "Language Filter" button in the upper left corner.
Claim
Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite
See
DataTable Class | DataTable Member | System.Data Name Space | AcceptChanges | DataRow | DataRowCollection | Newrow