DataRow.GetParentRow Method

Definition

Obtém a linha pai de um DataRow.Gets the parent row of a DataRow.

Overloads

GetParentRow(DataRelation)

Obtém a linha pai de um DataRow usando o DataRelation especificado.Gets the parent row of a DataRow using the specified DataRelation.

GetParentRow(String)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation.Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

GetParentRow(DataRelation, DataRowVersion)

Obtém a linha pai de um DataRow usando o DataRelatione DataRowVersion.Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

GetParentRow(String, DataRowVersion)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation e DataRowVersion.Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetParentRow(DataRelation)

Obtém a linha pai de um DataRow usando o DataRelation especificado.Gets the parent row of a DataRow using the specified DataRelation.

public:
 System::Data::DataRow ^ GetParentRow(System::Data::DataRelation ^ relation);
public System.Data.DataRow GetParentRow (System.Data.DataRelation relation);
member this.GetParentRow : System.Data.DataRelation -> System.Data.DataRow
Public Function GetParentRow (relation As DataRelation) As DataRow

Parameters

relation
DataRelation

O DataRelation a ser usado.The DataRelation to use.

Returns

DataRow

O DataRow pai da linha atual.The parent DataRow of the current row.

Exceptions

O relation não pertence ao DataTable.The relation does not belong to the DataTable.

-ou--or-

A linha é null.The row is null.

Uma linha filho tem vários pais.A child row has multiple parents.

Essa linha não pertence à tabela filho do objeto DataRelation.This row does not belong to the child table of the DataRelation object.

A linha não pertence a uma tabela.The row does not belong to a table.

Examples

O exemplo a seguir usa a GetParentRow para retornar os objetos de DataRow filho para cada DataRelation filho em um DataTable.The following example uses the GetParentRow to return the child DataRow objects for every child DataRelation in a DataTable. Em seguida, o valor de cada coluna na linha é impresso.The value of each column in the row is then printed.

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

private void CallGetParentRowForTable()
{
    // An example of calling the function.
    DataTable thisTable = DataSet1.Tables["Products"];
    DataRelation relation = thisTable.ParentRelations[0];
    GetParentRowForTable(thisTable, relation);
}
Private Sub GetParentRowForTable _
   (thisTable As DataTable, relation As DataRelation)
    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 row As DataRow
    For Each row In  thisTable.Rows
        parentRow = row.GetParentRow(relation)
        Console.Write(ControlChars.Tab & " child row: " _
           & row(1).ToString())
        Console.Write(ControlChars.Tab & " parent row: " _
           & parentRow(1).ToString() & ControlChars.Cr)
    Next row
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)
    GetParentRowForTable(thisTable, relation)
End Sub

Remarks

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

See also

GetParentRow(String)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation.Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

public:
 System::Data::DataRow ^ GetParentRow(System::String ^ relationName);
public System.Data.DataRow GetParentRow (string relationName);
member this.GetParentRow : string -> System.Data.DataRow
Public Function GetParentRow (relationName As String) As DataRow

Parameters

relationName
String

O RelationName de um DataRelation.The RelationName of a DataRelation.

Returns

DataRow

O DataRow pai da linha atual.The parent DataRow of the current row.

Exceptions

A relação e a linha não pertencem à mesma tabela.The relation and row do not belong to the same table.

Uma linha filho tem vários pais.A child row has multiple parents.

A linha não pertence à tabela.The row does not belong to the table.

Examples

O exemplo a seguir usa o GetParentRow para imprimir um valor de cada linha pai de cada DataRow em uma DataTable.The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.

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

private void CallGetParentRowForTable()
{
    // An example of calling the function.
    DataTable thisTable = DataSet1.Tables["Products"];
    DataRelation relation = thisTable.ParentRelations[0];
    GetParentRowForTable(thisTable, relation.RelationName);
}
Private Sub GetParentRowForTable( _
    thisTable As DataTable, relation As String)
     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 row As DataRow
     For Each row In  thisTable.Rows
         parentRow = row.GetParentRow(relation)
         Console.Write(ControlChars.Tab + " child row: " _
            + row(1).ToString())
         Console.Write(ControlChars.Tab + " parent row: " _
            + parentRow(1).ToString() + ControlChars.Cr)
     Next row
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)
     GetParentRowForTable(thisTable, relation.RelationName)
End Sub

Remarks

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

GetParentRow(DataRelation, DataRowVersion)

Obtém a linha pai de um DataRow usando o DataRelatione DataRowVersion.Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

public:
 System::Data::DataRow ^ GetParentRow(System::Data::DataRelation ^ relation, System::Data::DataRowVersion version);
public System.Data.DataRow GetParentRow (System.Data.DataRelation relation, System.Data.DataRowVersion version);
member this.GetParentRow : System.Data.DataRelation * System.Data.DataRowVersion -> System.Data.DataRow
Public Function GetParentRow (relation As DataRelation, version As DataRowVersion) As DataRow

Parameters

relation
DataRelation

O DataRelation a ser usado.The DataRelation to use.

version
DataRowVersion

Um dos valores de DataRowVersion especificando a versão dos dados a serem obtidos.One of the DataRowVersion values specifying the version of the data to get.

Returns

DataRow

O DataRow pai da linha atual.The parent DataRow of the current row.

Exceptions

A linha é null.The row is null.

-ou--or-

O relation não pertence às relações pai dessa tabela.The relation does not belong to this table's parent relations.

Uma linha filho tem vários pais.A child row has multiple parents.

A tabela filho da relação não é a tabela à qual a linha pertence.The relation's child table is not the table the row belongs to.

A linha não pertence a uma tabela.The row does not belong to a table.

A linha não tem esta versão de dados.The row does not have this version of data.

Examples

O exemplo a seguir usa a GetParentRow para retornar os objetos de DataRow filho para cada DataRelation filho em um DataTable.The following example uses the GetParentRow to return the child DataRow objects for every child DataRelation in a DataTable. Em seguida, o valor de cada coluna na linha é impresso.The value of each column in the row is then printed.

private void GetParentRowForTable(DataTable thisTable,
    DataRelation relation,
    DataRowVersion version)
{
    if(thisTable ==null){return;}
    // For each row in the table, print column 1 of the
    // parent DataRow.
    DataRow parentRow;
    foreach(DataRow row in thisTable.Rows)
    {
        parentRow = row.GetParentRow(relation, version);
        Console.Write("\table child row: " + row[1]);
        Console.Write("\table 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,
        DataRowVersion.Original);
}
Private Sub GetParentRowForTable _
    (thisTable As DataTable, relation As DataRelation, _
    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 row As DataRow
    For Each row In  thisTable.Rows
        parentRow = row.GetParentRow(relation, version)
        Console.Write(ControlChars.Tab & " child row: " & _
            row(1).ToString())
        Console.Write(ControlChars.Tab & " parent row: " _
            & parentRow(1).ToString() & ControlChars.Cr)
    Next row
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, _
        DataRowVersion.Original)
End Sub

Remarks

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

Use a propriedade HasVersion para determinar se o DataRowVersion desejado existe.Use the HasVersion property to determine whether the DataRowVersion that you want exists.

See also

GetParentRow(String, DataRowVersion)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation e DataRowVersion.Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

public:
 System::Data::DataRow ^ GetParentRow(System::String ^ relationName, System::Data::DataRowVersion version);
public System.Data.DataRow GetParentRow (string relationName, System.Data.DataRowVersion version);
member this.GetParentRow : string * System.Data.DataRowVersion -> System.Data.DataRow
Public Function GetParentRow (relationName As String, version As DataRowVersion) As DataRow

Parameters

relationName
String

O RelationName de um DataRelation.The RelationName of a DataRelation.

version
DataRowVersion

Um dos valores de DataRowVersion.One of the DataRowVersion values.

Returns

DataRow

O DataRow pai da linha atual.The parent DataRow of the current row.

Exceptions

A relação e a linha não pertencem à mesma tabela.The relation and row do not belong to the same table.

O relation é null.The relation is null.

Uma linha filho tem vários pais.A child row has multiple parents.

A linha não pertence à tabela.The row does not belong to the table.

A linha não tem o DataRowVersion solicitado.The row does not have the requested DataRowVersion.

Examples

O exemplo a seguir usa o GetParentRow para imprimir um valor de cada linha pai de cada DataRow em uma DataTable.The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.

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 row in thisTable.Rows)
    {
        parentRow = row.GetParentRow(relation, version);
        Console.Write("\t child row: " + row[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);
}
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 row As DataRow
     For Each row In  thisTable.Rows
         parentRow = row.GetParentRow(relation, version)
         Console.Write(ControlChars.Tab & " child row: " _
            & row(1).ToString())
         Console.Write(ControlChars.Tab & " parent row: " _
            & parentRow(1).ToString() & ControlChars.Cr)
     Next row
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

Remarks

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

Use a propriedade HasVersion para determinar se o DataRowVersion desejado existe.Use the HasVersion property to determine whether the DataRowVersion that you want exists.

Applies to