Export (0) Print
Expand All

DataTable.ParentRelations Property

Gets the collection of parent relations for this DataTable.

[Visual Basic]
Public ReadOnly Property ParentRelations As DataRelationCollection
[C#]
public DataRelationCollection ParentRelations {get;}
[C++]
public: __property DataRelationCollection* get_ParentRelations();
[JScript]
public function get ParentRelations() : DataRelationCollection;

Property Value

A DataRelationCollection that contains the parent relations for the table; otherwise a null value if no DataRelation objects exist.

Example

[Visual Basic, C#, C++] The following example uses the ParentRelations property to return each parent DataRelation in a DataTable. Each relation is then used as an argument in the GetParentRows method of the DataRow to return an array of rows. The value of each column in the row is then printed.

[Visual Basic] 
Private Sub GetChildRowsFromDataRelation(myTable As DataTable)
    Dim arrRows() As DataRow
    Dim myRel As DataRelation, myRow As DataRow
    Dim dc As DataColumn, i As Integer     
    For Each myRel In  myTable.ParentRelations
        For Each myRow In  myTable.Rows
            arrRows = myRow.GetParentRows(myRel)
            ' Print values of rows.             
            For i = 0 To arrRows.Length - 1                 
                For Each dc In  myTable.Columns
                    Console.WriteLine(arrRows(i)(dc))
                Next dc
            Next i
        Next myRow
    Next myRel
End Sub

[C#] 
private void GetChildRowsFromDataRelation(DataTable myTable){
   DataRow[] arrRows;
   foreach(DataRelation myRel in myTable.ParentRelations){
     foreach(DataRow myRow in myTable.Rows){
         arrRows = myRow.GetParentRows(myRel);
         // Print values of rows.
         for(int i = 0; i < arrRows.Length; i++){
            foreach(DataColumn dc in myTable.Columns){
               Console.WriteLine(arrRows[i][dc]);
            }
         }
      }
   }
}

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

[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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataTable Class | DataTable Members | System.Data Namespace | ChildRelations | DataRelation | DataSet | Relations

Show:
© 2014 Microsoft