DataTable.Rows DataTable.Rows DataTable.Rows DataTable.Rows Property


このテーブルに属する行のコレクションを取得します。Gets the collection of rows that belong to this table.

 property System::Data::DataRowCollection ^ Rows { System::Data::DataRowCollection ^ get(); };
public System.Data.DataRowCollection Rows { get; }
member this.Rows : System.Data.DataRowCollection
Public ReadOnly Property Rows As DataRowCollection


DataRowCollection オブジェクトが格納されている DataRowDataRow オブジェクトが存在しない場合は null 値。A DataRowCollection that contains DataRow objects; otherwise a null value if no DataRow objects exist.

設定する行を返し、2 つの例を次に示します。The following shows two examples of returning and setting rows. 最初の例では、Rowsプロパティを行ごとに各列の値を出力します。The first example uses the Rows property and prints the value of each column for every row. 2 番目の例では、DataTableオブジェクトのNewRow新たに作成するメソッドDataRowのスキーマ オブジェクトをDataTableします。The second example uses the DataTable object's NewRow method to create a new DataRow object with the schema of the DataTable. 行を追加する行の値を設定した後、DataRowCollectionを通じて、Addメソッド。After setting the row values, the row is added to the DataRowCollection through the Add method.

private void PrintRows(DataSet dataSet)
    // For each table in the DataSet, print the values of each row.
    foreach(DataTable thisTable in dataSet.Tables)
        // For each row, print the values of each column.
        foreach(DataRow row in thisTable.Rows)
            foreach(DataColumn column in thisTable.Columns)

private void AddARow(DataSet dataSet)
    DataTable table;
    table = dataSet.Tables["Suppliers"];
    // Use the NewRow method to create a DataRow with 
    // the table's schema.
    DataRow newRow = table.NewRow();

    // Set values in the columns:
    newRow["CompanyID"] = "NewCompanyID";
    newRow["CompanyName"] = "NewCompanyName";

    // Add the row to the rows collection.
Private Sub PrintRows(dataSet As DataSet)
     ' For each table in the DataSet, print the values of each row.
     Dim thisTable As DataTable
     For Each thisTable In  dataSet.Tables
         ' For each row, print the values of each column.
         Dim row As DataRow
         For Each row In  thisTable.Rows
             Dim column As DataColumn
             For Each column In  thisTable.Columns
             Next column
         Next row
     Next thisTable
End Sub
Private Sub AddARow(dataSet As DataSet)
    Dim table As DataTable = dataSet.Tables("Suppliers")
    ' Use the NewRow method to create a DataRow 
    'with the table's schema.
    Dim newRow As DataRow = table.NewRow()

    ' Set values in the columns:
    newRow("CompanyID") = "NewCompanyID"
    newRow("CompanyName") = "NewCompanyName"

    ' Add the row to the rows collection.
End Sub


新たに作成するDataRow、使用する必要があります、NewRow新しいオブジェクトを返すメソッド。To create a new DataRow, you must use the NewRow method to return a new object. このようなオブジェクトが自動的に構成に定義されたスキーマに従って、DataTableのコレクションをDataColumnオブジェクト。Such an object is automatically configured according to the schema defined for the DataTable through its collection of DataColumn objects. 新しい行を作成し、行の各列の値を設定した後に行を追加、DataRowCollectionを使用して、Addメソッド。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.

DataRowコレクション内には、テーブル内のデータの行を表します。Each DataRow in the collection represents a row of data in the table. 行内の列の値に変更をコミットするを呼び出す必要があります、AcceptChangesメソッド。To commit a change to the value of a column in the row, you must invoke the AcceptChanges method.