DataRow.GetParentRow Método

Definição

Obtém a linha pai de um DataRow.

Sobrecargas

GetParentRow(DataRelation)

Obtém a linha pai de um DataRow usando o DataRelation especificado.

GetParentRow(String)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation.

GetParentRow(DataRelation, DataRowVersion)

Obtém a linha pai de um DataRow usando o DataRelatione DataRowVersion.

GetParentRow(String, DataRowVersion)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation e DataRowVersion.

GetParentRow(DataRelation)

Obtém a linha pai de um DataRow usando o DataRelation especificado.

public:
 System::Data::DataRow ^ GetParentRow(System::Data::DataRelation ^ relation);
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

Parâmetros

relation
DataRelation

O DataRelation a ser usado.

Retornos

DataRow

O DataRow pai da linha atual.

Exceções

O relation não pertence ao DataTable.

- ou -

A linha é null.

Uma linha filho tem vários pais.

Essa linha não pertence à tabela filho do objeto DataRelation.

A linha não pertence a uma tabela.

Exemplos

O exemplo a seguir usa o GetParentRow para retornar os objetos filho DataRow para cada filho DataRelation em um DataTable. Em seguida, o valor de cada coluna na linha é impresso.

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

Comentários

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.

Confira também

Aplica-se a

GetParentRow(String)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation.

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

Parâmetros

relationName
String

O RelationName de um DataRelation.

Retornos

DataRow

O DataRow pai da linha atual.

Exceções

A relação e a linha não pertencem à mesma tabela.

Uma linha filho tem vários pais.

A linha não pertence à tabela.

Exemplos

O exemplo a seguir usa o GetParentRow para imprimir um valor de cada linha pai de cada DataRow uma em um 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

Comentários

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.

Aplica-se a

GetParentRow(DataRelation, DataRowVersion)

Obtém a linha pai de um DataRow usando o DataRelatione 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);
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

Parâmetros

relation
DataRelation

O DataRelation a ser usado.

version
DataRowVersion

Um dos valores de DataRowVersion especificando a versão dos dados a serem obtidos.

Retornos

DataRow

O DataRow pai da linha atual.

Exceções

A linha é null.

- ou -

O relation não pertence às relações pai dessa tabela.

Uma linha filho tem vários pais.

A tabela filho da relação não é a tabela à qual a linha pertence.

A linha não pertence a uma tabela.

A linha não tem esta versão de dados.

Exemplos

O exemplo a seguir usa o GetParentRow para retornar os objetos filho DataRow para cada filho DataRelation em um DataTable. Em seguida, o valor de cada coluna na linha é impresso.

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

Comentários

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.

Use a propriedade HasVersion para determinar se o DataRowVersion desejado existe.

Confira também

Aplica-se a

GetParentRow(String, DataRowVersion)

Obtém a linha pai de um DataRow usando o RelationName especificado de uma DataRelation e DataRowVersion.

public:
 System::Data::DataRow ^ GetParentRow(System::String ^ relationName, System::Data::DataRowVersion version);
public System.Data.DataRow? GetParentRow (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

Parâmetros

relationName
String

O RelationName de um DataRelation.

version
DataRowVersion

Um dos valores de DataRowVersion.

Retornos

DataRow

O DataRow pai da linha atual.

Exceções

A relação e a linha não pertencem à mesma tabela.

O relation é null.

Uma linha filho tem vários pais.

A linha não pertence à tabela.

A linha não tem o DataRowVersion solicitado.

Exemplos

O exemplo a seguir usa o GetParentRow para imprimir um valor de cada linha pai de cada DataRow uma em um 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

Comentários

Em um DataSet, a coleção de todos os objetos pai de DataRelation para o conjunto de dados é retornada pelo método GetParentRows.

O DataTable também contém uma coleção de objetos DataRelation, retornada pela propriedade ParentRelations.

Use a propriedade HasVersion para determinar se o DataRowVersion desejado existe.

Aplica-se a