次の方法で共有


DataRow.GetChildRows メソッド (DataRelation, DataRowVersion)

指定した DataRelationDataRowVersion を使用して、 DataRow の子行を取得します。

Overloads Public Function GetChildRows( _
   ByVal relation As DataRelation, _   ByVal version As DataRowVersion _) As DataRow()
[C#]
public DataRow[] GetChildRows(DataRelationrelation,DataRowVersionversion);
[C++]
public: DataRow* GetChildRows(DataRelation* relation,DataRowVersionversion) [];
[JScript]
public function GetChildRows(
   relation : DataRelation,version : DataRowVersion) : DataRow[];

パラメータ

  • relation
    使用する DataRelation
  • version
    取得するデータのバージョンを指定する DataRowVersion 値の 1 つ。可能な値は、Default、Original、Current、および Proposed です。

戻り値

DataRow オブジェクトの配列。

例外

例外の種類 条件
ArgumentException リレーションシップと行が同じテーブルに属していません。
ArgumentNullException relation が null 参照 (Visual Basic では Nothing) です。
RowNotInTableException 行がこのテーブルに属していません。
VersionNotFoundException 要求された DataRowVersion が行にありません。

解説

DataTable は、 ChildRelations プロパティが返す DataRelation オブジェクトのコレクションも格納します。

目的の DataRowVersion が存在するかどうかを確認するには、 HasVersion プロパティを使用します。

使用例

[Visual Basic, C#, C++] GetChildRows を使用して、 DataTable 内の各子 DataRelation の子 DataRow オブジェクトを返す例を次に示します。行内の指定したバージョンの各列の値が出力されます。

 
Private Sub GetChildRowsFromDataRelation(myTable As DataTable)
    Dim myRelation As DataRelation
    Dim arrRows() As DataRow
    Dim myRow As DataRow
    Dim i As Integer
    Dim myColumn As DataColumn 
 
    For Each myRelation In myTable.ChildRelations
      For Each myRow In myTable.Rows
          arrRows = myRow.GetChildRows(myRelation, DataRowVersion.Proposed)
          ' Print values of rows.
          For i = 0 To arrRows.GetUpperBound(0)
             For Each myColumn in myTable.Columns
                Console.WriteLine(arrRows(i)(myColumn))
             Next myColumn
          Next i
       Next myRow
    Next myRelation
 End Sub

[C#] 
private void GetChildRowsFromDataRelation(DataTable myTable ) {
    DataRow[] arrRows;  
    foreach(DataRelation myRelation in myTable.ChildRelations){
       foreach(DataRow myRow in myTable.Rows){
          arrRows = myRow.GetChildRows(myRelation, DataRowVersion.Proposed);
          // Print values of rows.
          for(int i = 0; i < arrRows.Length; i++){
             foreach(DataColumn myColumn in myTable.Columns){
                Console.WriteLine(arrRows[i][myColumn]);
             }
          }
       }
    }
 }

[C++] 
private:
void GetChildRowsFromDataRelation(DataTable* myTable ) {
    DataRow* arrRows[];  
    System::Collections::IEnumerator* myEnum = myTable->ChildRelations->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataRelation* myRelation = __try_cast<DataRelation*>(myEnum->Current);
       System::Collections::IEnumerator* myEnum1 = myTable->Rows->GetEnumerator();
       while (myEnum1->MoveNext())
       {
          DataRow* myRow = __try_cast<DataRow*>(myEnum1->Current);
          arrRows = myRow->GetChildRows(myRelation, DataRowVersion::Proposed);
          // Print values of rows.
          for(int i = 0; i < arrRows->Length; i++){
             System::Collections::IEnumerator* myEnum2 = myTable->Columns->GetEnumerator();
             while (myEnum2->MoveNext())
             {
                DataColumn* myColumn = __try_cast<DataColumn*>(myEnum2->Current);
                Console::WriteLine(arrRows[i]->Item[myColumn]);
             }
          }
       }
    }
 }

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

必要条件

プラットフォーム: 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

参照

DataRow クラス | DataRow メンバ | System.Data 名前空間 | DataRow.GetChildRows オーバーロードの一覧 | ChildRelations | DataRelation | DataRowVersion | GetParentRow | GetParentRows | Relations