DataTable.Rows プロパティ
アセンブリ: System.Data (system.data.dll 内)


新しい DataRow を作成するには、NewRow メソッドを使用して、新しいオブジェクトを返す必要があります。このようなオブジェクトは、DataColumn オブジェクトのコレクションを通じて DataTable に対して定義されたスキーマに従って、自動的に設定されます。新しい行を作成し、行内の各列の値を設定した後、Add メソッドを使用してこの行を DataRowCollection に追加します。
コレクション内の各 DataRow は、テーブル内のデータ行を表します。行内の列の値に対して行った変更をコミットするには、AcceptChanges メソッドを呼び出す必要があります。

行を返し、設定する 2 つの例を次に示します。最初の例では、Rows プロパティを使用し、各行の各列の値を出力します。2 番目の例では、DataTable オブジェクトの NewRow メソッドを使用して、DataTable のスキーマで新しい DataRow オブジェクトを作成します。行の値を設定した後、Add メソッドを使用してこの行を DataRowCollection に追加します。
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
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); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDataTable.Rows プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataTable.Rows プロパティのページへのリンク