Export (0) Print
Expand All

DataRow.GetParentRow Method

Gets the parent row of a DataRow.

Overload List

Gets the parent row of a DataRow using the specified DataRelation.

Supported by the .NET Compact Framework.

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

Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

Supported by the .NET Compact Framework.

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

Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

Supported by the .NET Compact Framework.

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

Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

Supported by the .NET Compact Framework.

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

Example

[Visual Basic, C#, C++] The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetParentRow. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub GetParentRowForTable _
(thisTable As DataTable, relation As String, version As DataRowVersion)
    If thisTable Is Nothing Then
        Return
    End If
    ' For each row in the table, print column 1 of the parent DataRow.
    Dim parentRow As DataRow
    Dim r As DataRow
    For Each r In  thisTable.Rows
        parentRow = r.GetParentRow(relation, version)
        Console.Write(ControlChars.Tab + " child row: " + r(1).ToString())
        Console.Write(ControlChars.Tab + " parent row: " _
           + parentRow(1).ToString() + ControlChars.Cr)
    Next r
End Sub
  
Private Sub CallGetParentRowForTable()
    ' An example of calling the function.
    Dim thisTable As DataTable = DataSet1.Tables("Products")
    Dim relation As DataRelation = thisTable.ParentRelations(0)
    ' Print only original versions of parent rows.
    GetParentRowForTable(thisTable, relation.RelationName, _
       DataRowVersion.Original)
End Sub

[C#] 
private void GetParentRowForTable(DataTable thisTable, string relation, DataRowVersion version){
   if(thisTable ==null){return;}
   // For each row in the table, print column 1 of the parent DataRow.
   DataRow parentRow;
   foreach(DataRow r in thisTable.Rows){
      parentRow = r.GetParentRow(relation, version);
      Console.Write("\t child row: " + r[1]);
      Console.Write("\t parent row: " + parentRow[1]+ "\n");
   }
}

private void CallGetParentRowForTable(){
   // An example of calling the function.
   DataTable thisTable = DataSet1.Tables["Products"];
   DataRelation relation = thisTable.ParentRelations[0];
   // Print only original versions of parent rows.
   GetParentRowForTable(thisTable, relation.RelationName,
      DataRowVersion.Original);
}

[C++] 
private:
 void GetParentRowForTable(DataTable* thisTable, String* relation, DataRowVersion version){
    if(thisTable ==0){return;}
    // For each row in the table, print column 1 of the parent DataRow.
    DataRow* parentRow;
    System::Collections::IEnumerator* myEnum = thisTable->Rows->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataRow* r = __try_cast<DataRow*>(myEnum->Current);
       parentRow = r->GetParentRow(relation, version);
       Console::Write(S"\t child row: {0}", r->Item[1]);
       Console::Write(S"\t parent row: {0}\n", parentRow->Item[1]);
    }
 }
 
 void CallGetParentRowForTable(){
    // An example of calling the function.
    DataTable* thisTable = DataSet1->Tables->Item[S"Products"];
    DataRelation* relation = thisTable->ParentRelations->Item[0];
    // Print only original versions of parent rows.
    GetParentRowForTable(thisTable, relation->RelationName,
       DataRowVersion::Original);
 }

[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:
© 2015 Microsoft