This documentation is archived and is not being maintained.

DataRow.GetChildRows Method

Gets the child rows of a DataRow.

Overload List

Gets the child rows of this DataRow using the specified DataRelation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetChildRows(DataRelation) As DataRow()
[C#] public DataRow[] GetChildRows(DataRelation);
[C++] public: DataRow* GetChildRows(DataRelation*) [];
[JScript] public function GetChildRows(DataRelation) : DataRow[];

Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetChildRows(String) As DataRow()
[C#] public DataRow[] GetChildRows(string);
[C++] public: DataRow* GetChildRows(String*) [];
[JScript] public function GetChildRows(String) : DataRow[];

Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetChildRows(DataRelation, DataRowVersion) As DataRow()
[C#] public DataRow[] GetChildRows(DataRelation, DataRowVersion);
[C++] public: DataRow* GetChildRows(DataRelation*, DataRowVersion) [];
[JScript] public function GetChildRows(DataRelation, DataRowVersion) : DataRow[];

Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetChildRows(String, DataRowVersion) As DataRow()
[C#] public DataRow[] GetChildRows(string, DataRowVersion);
[C++] public: DataRow* GetChildRows(String*, DataRowVersion) [];
[JScript] public function GetChildRows(String, DataRowVersion) : DataRow[];

Example

[Visual Basic, C#, C++] The following example uses the GetChildRows to return the child DataRow objects for every child DataRelation in a DataTable. The value of each column with the specified version in the row is then printed.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetChildRows. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataRow Class | DataRow Members | System.Data Namespace

Show: