DataRow.GetParentRow Méthode

Définition

Obtient la ligne parente de DataRow.

Surcharges

GetParentRow(DataRelation)

Obtient la ligne parente de DataRow à l'aide du DataRelation spécifié.

GetParentRow(String)

Obtient la ligne parente de DataRow à l'aide du RelationName spécifié de DataRelation.

GetParentRow(DataRelation, DataRowVersion)

Obtient la ligne parente de DataRow à l'aide du DataRelation et du DataRowVersion spécifiés.

GetParentRow(String, DataRowVersion)

Obtient la ligne parente de DataRow à l'aide du RelationName spécifié de DataRelation et de DataRowVersion.

GetParentRow(DataRelation)

Obtient la ligne parente de DataRow à l'aide du DataRelation spécifié.

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

Paramètres

relation
DataRelation

DataRelation à utiliser.

Retours

DataRow

DataRow parent de la ligne en cours.

Exceptions

relation n'appartient pas à DataTable.

  • ou -

La ligne est null.

Une ligne enfant a plusieurs parents.

Cette ligne n'appartient pas à la table enfant de l'objet DataRelation.

La ligne n'appartient pas à une table.

Exemples

L’exemple suivant utilise l’exemple GetParentRow suivant pour retourner les objets enfants DataRow pour chaque enfant DataRelation d’un DataTable. La valeur de chaque colonne de la ligne est ensuite imprimée.

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

Remarques

Dans un DataSet, la collection de tous les objets parents DataRelation pour le jeu de données est retournée par la GetParentRows méthode.

Il DataTable contient également une collection d’objets DataRelation , retournée par la ParentRelations propriété.

Voir aussi

S’applique à

GetParentRow(String)

Obtient la ligne parente de DataRow à l'aide du RelationName spécifié de 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

Paramètres

relationName
String

RelationName de DataRelation.

Retours

DataRow

DataRow parent de la ligne en cours.

Exceptions

La relation et la ligne n'appartiennent pas à la même table.

Une ligne enfant a plusieurs parents.

La ligne n'appartient pas à la table.

Exemples

L’exemple suivant utilise l’exemple GetParentRow suivant pour imprimer une valeur de chaque ligne parente de chacune DataRow d’elles dans un 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

Remarques

Dans un DataSet, la collection de tous les objets parents DataRelation pour le jeu de données est retournée par la GetParentRows méthode.

Il DataTable contient également une collection d’objets DataRelation , retournée par la ParentRelations propriété.

S’applique à

GetParentRow(DataRelation, DataRowVersion)

Obtient la ligne parente de DataRow à l'aide du DataRelation et du DataRowVersion spécifiés.

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

Paramètres

relation
DataRelation

DataRelation à utiliser.

version
DataRowVersion

Une des valeurs DataRowVersion spécifiant la version des données à obtenir.

Retours

DataRow

DataRow parent de la ligne en cours.

Exceptions

La ligne est null.

  • ou -

relation n'appartient pas aux relations parentes de cette table.

Une ligne enfant a plusieurs parents.

La table enfant de la relation n'est pas la table à laquelle appartient la ligne.

La ligne n'appartient pas à une table.

La ligne ne possède pas cette version des données.

Exemples

L’exemple suivant utilise l’exemple GetParentRow suivant pour retourner les objets enfants DataRow pour chaque enfant DataRelation d’un DataTable. La valeur de chaque colonne de la ligne est ensuite imprimée.

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

Remarques

Dans un DataSet, la collection de tous les objets parents DataRelation pour le jeu de données est retournée par la GetParentRows méthode.

Il DataTable contient également une collection d’objets DataRelation , retournée par la ParentRelations propriété.

Utilisez la HasVersion propriété pour déterminer si vous DataRowVersion souhaitez exister.

Voir aussi

S’applique à

GetParentRow(String, DataRowVersion)

Obtient la ligne parente de DataRow à l'aide du RelationName spécifié de DataRelation et de 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

Paramètres

relationName
String

RelationName de DataRelation.

version
DataRowVersion

Une des valeurs de l'objet DataRowVersion.

Retours

DataRow

DataRow parent de la ligne en cours.

Exceptions

La relation et la ligne n'appartiennent pas à la même table.

relation a la valeur null.

Une ligne enfant a plusieurs parents.

La ligne n'appartient pas à la table.

La ligne ne contient pas le DataRowVersion demandé.

Exemples

L’exemple suivant utilise l’exemple GetParentRow suivant pour imprimer une valeur de chaque ligne parente de chacune DataRow d’elles dans un 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

Remarques

Dans un DataSet, la collection de tous les objets parents DataRelation pour le jeu de données est retournée par la GetParentRows méthode.

Il DataTable contient également une collection d’objets DataRelation , retournée par la ParentRelations propriété.

Utilisez la HasVersion propriété pour déterminer si vous DataRowVersion souhaitez exister.

S’applique à