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
プロパティ値
DataRow オブジェクトを含むDataRowCollection。
- 属性
例
行の取得と設定の 2 つの例を次に示します。 最初の例では、 Rows プロパティを使用し、各行の各列の値を出力します。 2 番目の例では、DataTable オブジェクトの NewRow メソッドを使用して、DataTableのスキーマを持つ新しいDataRow オブジェクトを作成します。 行の値を設定すると、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に対して定義されたスキーマに従って自動的に構成されます。 新しい行を作成し、行の各列の値を設定した後、Add メソッドを使用して行をDataRowCollectionに追加します。
コレクション内の各 DataRow は、テーブル内のデータ行を表します。 行内の列の値に変更をコミットするには、 AcceptChanges メソッドを呼び出す必要があります。