DataRow.GetParentRow 方法

定义

获取 DataRow 的父行。Gets the parent row of a DataRow.

重载

GetParentRow(DataRelation)

使用指定的 DataRelation 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified DataRelation.

GetParentRow(String)

使用 DataRelation 的指定 RelationName 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

GetParentRow(DataRelation, DataRowVersion)

使用指定的 DataRelationDataRowVersion 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

GetParentRow(String, DataRowVersion)

使用 DataRelation 的指定 RelationNameDataRowVersion 获取 DataRow 的父行。Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetParentRow(DataRelation)

使用指定的 DataRelation 获取 DataRow 的父行。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);
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

参数

relation
DataRelation

要使用的 DataRelationThe DataRelation to use.

返回

DataRow

当前行的父 DataRowThe parent DataRow of the current row.

例外

relation 不属于 DataTableThe relation does not belong to the DataTable.

- 或 --or-

该行为 nullThe row is null.

子行具有多个父行。A child row has multiple parents.

此行不属于 DataRelation 对象的子表。This row does not belong to the child table of the DataRelation object.

此行不属于表。The row does not belong to a table.

示例

下面的示例使用 GetParentRow 返回 DataRow 中每个子对象的子对象 DataRelation DataTableThe following example uses the GetParentRow to return the child DataRow objects for every child DataRelation in a DataTable. 然后打印该行中每列的值。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

注解

在中 DataSet ,该数据集的所有父对象的集合 DataRelationGetParentRows 方法返回。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable还包含 DataRelation 由属性返回的对象的集合 ParentRelationsThe DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

另请参阅

适用于

GetParentRow(String)

使用 DataRelation 的指定 RelationName 获取 DataRow 的父行。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);
public System.Data.DataRow GetParentRow (string relationName);
member this.GetParentRow : string -> System.Data.DataRow
Public Function GetParentRow (relationName As String) As DataRow

参数

返回

DataRow

当前行的父 DataRowThe parent DataRow of the current row.

例外

关系和行不属于同一个表。The relation and row do not belong to the same table.

子行具有多个父行。A child row has multiple parents.

此行不属于该表。The row does not belong to the table.

示例

下面的示例使用 GetParentRow 从中每个的父行打印一个值 DataRow DataTableThe 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

注解

在中 DataSet ,该数据集的所有父对象的集合 DataRelationGetParentRows 方法返回。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable还包含 DataRelation 由属性返回的对象的集合 ParentRelationsThe DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

适用于

GetParentRow(DataRelation, DataRowVersion)

使用指定的 DataRelationDataRowVersion 获取 DataRow 的父行。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);
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

参数

relation
DataRelation

要使用的 DataRelationThe DataRelation to use.

version
DataRowVersion

DataRowVersion 值之一,指定要获取的数据的版本。One of the DataRowVersion values specifying the version of the data to get.

返回

DataRow

当前行的父 DataRowThe parent DataRow of the current row.

例外

该行为 nullThe row is null.

- 或 --or-

relation 不属于该表的父关系。The relation does not belong to this table's parent relations.

子行具有多个父行。A child row has multiple parents.

此关系的子表不是该行所属的表。The relation's child table is not the table the row belongs to.

此行不属于表。The row does not belong to a table.

该行没有此版本的数据。The row does not have this version of data.

示例

下面的示例使用 GetParentRow 返回 DataRow 中每个子对象的子对象 DataRelation DataTableThe following example uses the GetParentRow to return the child DataRow objects for every child DataRelation in a DataTable. 然后打印该行中每列的值。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

注解

在中 DataSet ,该数据集的所有父对象的集合 DataRelationGetParentRows 方法返回。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable还包含 DataRelation 由属性返回的对象的集合 ParentRelationsThe DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

使用 HasVersion 属性来确定是否存在所 DataRowVersion 需的。Use the HasVersion property to determine whether the DataRowVersion that you want exists.

另请参阅

适用于

GetParentRow(String, DataRowVersion)

使用 DataRelation 的指定 RelationNameDataRowVersion 获取 DataRow 的父行。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);
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

参数

version
DataRowVersion

DataRowVersion 值之一。One of the DataRowVersion values.

返回

DataRow

当前行的父 DataRowThe parent DataRow of the current row.

例外

关系和行不属于同一个表。The relation and row do not belong to the same table.

relationnullThe relation is null.

子行具有多个父行。A child row has multiple parents.

此行不属于该表。The row does not belong to the table.

该行没有请求的 DataRowVersionThe row does not have the requested DataRowVersion.

示例

下面的示例使用 GetParentRow 从中每个的父行打印一个值 DataRow DataTableThe 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

注解

在中 DataSet ,该数据集的所有父对象的集合 DataRelationGetParentRows 方法返回。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable还包含 DataRelation 由属性返回的对象的集合 ParentRelationsThe DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

使用 HasVersion 属性来确定是否存在所 DataRowVersion 需的。Use the HasVersion property to determine whether the DataRowVersion that you want exists.

适用于