DataTable.Rows プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
このテーブルに属する行のコレクションを取得します。
public:
property System::Data::DataRowCollection ^ Rows { System::Data::DataRowCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Data.DataRowCollection Rows { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableRowsDescr")]
public System.Data.DataRowCollection Rows { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Rows : System.Data.DataRowCollection
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableRowsDescr")>]
member this.Rows : System.Data.DataRowCollection
Public ReadOnly Property Rows As DataRowCollection
プロパティ値
DataRowCollection オブジェクトを含む DataRow。
- 属性
例
行の取得と設定の 2 つの例を次に示します。 最初の例では、プロパティを Rows 使用し、各行の各列の値を出力します。 2 番目の例では、DataTableオブジェクトのNewRowメソッドを使用して、DataRowDataTable. 行の値を設定すると、メソッドを通じて行がAdd
追加されますDataRowCollection。
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)
{
Console.WriteLine(row[column]);
}
}
}
}
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.
table.Rows.Add(newRow);
}
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
Console.WriteLine(row(column))
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.
table.Rows.Add(newRow)
End Sub
注釈
新 DataRowしいオブジェクトを作成するには、メソッドを NewRow 使用して新しいオブジェクトを返す必要があります。 このようなオブジェクトは、オブジェクトのコレクションDataColumnを通じて定義されたスキーマにDataTable従って自動的に構成されます。 新しい行を作成し、行の各列の値を設定した後、メソッドを使用して行をDataRowCollectionAdd
追加します。
コレクション内のそれぞれ DataRow は、テーブル内のデータ行を表します。 行内の列の値に変更をコミットするには、メソッドを AcceptChanges 呼び出す必要があります。