语言

DataRow.GetParentRow 方法

定义

获取一个 DataRow. 的父行。

重载

名称 说明
GetParentRow(DataRelation)

获取使用指定DataRow项的DataRelation父行。

GetParentRow(String)

获取使用指定DataRowRelationName项的DataRelation父行。

GetParentRow(DataRelation, DataRowVersion)

获取使用指定项的DataRow父行,以及 DataRelation。DataRowVersion

GetParentRow(String, DataRowVersion)

获取使用指定DataRowRelationName项的DataRelation父行,以及 DataRowVersion。

GetParentRow(DataRelation)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

获取使用指定DataRow项的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

要使用的 DataRelation 。

返回

当前行的父 DataRow 级。

例外

不属于 relation .DataTable

-或-

行为 null.

子行具有多个父级。

此行不属于对象的子表 DataRelation 。

该行不属于表。

示例

以下示例使用 > 返回每个子项的子对象。 然后打印行中每列的值。

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中,数据集的所有父 DataRelation 对象的集合由 GetParentRows 该方法返回。

它还DataTable包含属性返回DataRelation的对象ParentRelations集合。

另请参阅

适用于

GetParentRow(String)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

获取使用指定DataRowRelationName项的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

参数

relationName
String

的 RelationNameDataRelation.

返回

当前行的父 DataRow 级。

例外

关系和行不属于同一个表。

子行具有多个父级。

该行不属于该表。

示例

下面的示例使用 > 打印每个父行 中的 值。

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中,数据集的所有父 DataRelation 对象的集合由 GetParentRows 该方法返回。

它还DataTable包含属性返回DataRelation的对象ParentRelations集合。

适用于

GetParentRow(DataRelation, DataRowVersion)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

获取使用指定项的DataRow父行,以及 DataRelation。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

要使用的 DataRelation 。

version
DataRowVersion

DataRowVersion指定要获取的数据版本的值之一。

返回

当前行的父 DataRow 级。

例外

行为 null.

-或-

该 relation 表不属于此表的父关系。

子行具有多个父级。

关系子表不是行所属的表。

该行不属于表。

该行没有此版本的数据。

示例

以下示例使用 > 返回每个子项的子对象。 然后打印行中每列的值。

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中,数据集的所有父 DataRelation 对象的集合由 GetParentRows 该方法返回。

它还DataTable包含属性返回DataRelation的对象ParentRelations集合。

使用属性 HasVersion 确定 DataRowVersion 所需的是否存在。

另请参阅

适用于

GetParentRow(String, DataRowVersion)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

获取使用指定DataRowRelationName项的DataRelation父行,以及 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

参数

relationName
String

的 RelationNameDataRelation.

version
DataRowVersion

其中一个 DataRowVersion 值。

返回

当前行的父 DataRow 级。

例外

关系和行不属于同一个表。

子行具有多个父级。

该行不属于该表。

示例

下面的示例使用 > 打印每个父行 中的 值。

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中,数据集的所有父 DataRelation 对象的集合由 GetParentRows 该方法返回。

它还DataTable包含属性返回DataRelation的对象ParentRelations集合。

使用属性 HasVersion 确定 DataRowVersion 所需的是否存在。

适用于