次の方法で共有


DataRowCollection クラス

DataTable の行のコレクションを表します。

この型のすべてのメンバの一覧については、DataRowCollection メンバ を参照してください。

System.Object
   System.Data.InternalDataCollectionBase
      System.Data.DataRowCollection

<Serializable>
Public Class DataRowCollection   Inherits InternalDataCollectionBase
[C#]
[Serializable]
public class DataRowCollection : InternalDataCollectionBase
[C++]
[Serializable]
public __gc class DataRowCollection : public   InternalDataCollectionBase
[JScript]
public
   Serializable
class DataRowCollection extends InternalDataCollectionBase

スレッドセーフ

この型は、マルチスレッド読み取り操作に対して安全です。すべての書き込み操作の同期をとる必要があります。

解説

DataRowCollectionDataTable の主要コンポーネントです。 DataColumnCollection がテーブルのスキーマを定義するのに対して、 DataRowCollection はテーブルの実際のデータを格納します。 DataRowCollection に格納された各 DataRow は単一行を表します。

DataRowCollectionDataRow オブジェクトを挿入するには Add メソッドを呼び出し、オブジェクトを削除するには Remove メソッドを呼び出します。主キー列内の特定の値を格納する DataRow オブジェクトを検索するには Find メソッドを呼び出し、文字ベースのデータ内にある単一の単語または語句を検索するには Contains メソッドを呼び出します。

使用例

[Visual Basic, C#, C++] 最初の例は、 DataRowCollection 内の各行の列 1 の値を出力します。2 番目の例は、 NewRow メソッドで作成した新しい行を DataRowCollection に追加します。

 
Private Sub ShowRows(Byval myTable As DataTable)
    ' Print the number of rows in the collection.
    Console.WriteLine(myTable.Rows.Count)
    Dim row  As DataRow
    ' Print the value of columns 1 in each row
    For Each row In myTable.Rows
        Console.WriteLine(row(1))
    Next
 End Sub
 
 Private Sub AddRow(ByVal myTable As DataTable)
    Dim newRow As DataRow
    ' Instantiate a new row using the NewRow method.
    newRow = myTable.NewRow()
    ' Insert code to fill the row with values.
    ' Add the row to the DataRowCollection.
    myTable.Rows.Add(newRow)
 End Sub

[C#] 
private void ShowRows(DataTable myTable){
    // Print the number of rows in the collection.
    Console.WriteLine(myTable.Rows.Count);
    // Print the value of columns 1 in each row
    foreach(DataRow row in myTable.Rows){
        Console.WriteLine(row[1]);
    }
 }
 
 private void AddRow(DataTable myTable){
    DataRow newRow;
    DataRowCollection rc = myTable.Rows;
    // Instantiate a new row using the NewRow method.
    newRow = myTable.NewRow();
    // Insert code to fill the row with values.
    // Add the row to the DataRowCollection.
    myTable.Rows.Add(newRow);
 }

[C++] 
private:
void ShowRows(DataTable* myTable){
    // Print the number of rows in the collection.
    Console::WriteLine(myTable->Rows->Count);
    // Print the value of columns 1 in each row
    System::Collections::IEnumerator* myEnum = myTable->Rows->GetEnumerator();
    while (myEnum->MoveNext())
    {
        DataRow* row = __try_cast<DataRow*>(myEnum->Current);
        Console::WriteLine(row->Item[1]);
    }
 }
 
 void AddRow(DataTable* myTable){
    DataRow* newRow;
    DataRowCollection* rc = myTable->Rows;
    // Instantiate a new row using the NewRow method.
    newRow = myTable->NewRow();
    // Insert code to fill the row with values.
    // Add the row to the DataRowCollection.
    myTable->Rows->Add(newRow);
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Data

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Data (System.Data.dll 内)

参照

DataRowCollection メンバ | System.Data 名前空間 | DataRow | DataTable | NewRow