DataRow.GetParentRow 方法

定義

取得 DataRow 的父資料列。

多載

GetParentRow(DataRelation)

使用指定的 DataRow,取得 DataRelation 的父資料列。

GetParentRow(String)

使用 DataRow 的指定 RelationName,取得 DataRelation 的父資料列。

GetParentRow(DataRelation, DataRowVersion)

使用指定的 DataRowDataRelation,取得 DataRowVersion 的父資料列。

GetParentRow(String, DataRowVersion)

使用 DataRow 的指定 RelationNameDataRelation,取得 DataRowVersion 的父資料列。

GetParentRow(DataRelation)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
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 物件的子資料表。

資料列不屬於資料表。

範例

下列範例會使用 GetParentRow 傳回 中每個子系的DataTableDataRowDataRelation物件。 接著會列印數據列中每個數據行的值。

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,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

DataTable也包含屬性所ParentRelations傳回的物件DataRelation集合。

另請參閱

適用於

GetParentRow(String)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
DataRow.cs

使用 DataRow 的指定 RelationName,取得 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

例外狀況

關聯和資料列不屬於相同資料表。

子資料行有多個父代。

資料列不屬於資料表。

範例

下列範例會使用 GetParentRow ,從中DataTable每個 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,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

DataTable也包含屬性所ParentRelations傳回的物件DataRelation集合。

適用於

GetParentRow(DataRelation, DataRowVersion)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
DataRow.cs

使用指定的 DataRowDataRelation,取得 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 不屬於這個資料表的父關聯。

子資料行有多個父代。

關聯的子資料表不是資料列所屬的資料表。

資料列不屬於資料表。

資料列沒有這個版本的資料。

範例

下列範例會使用 GetParentRow 傳回 中每個子系的DataTableDataRowDataRelation物件。 接著會列印數據列中每個數據行的值。

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,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

DataTable也包含屬性所ParentRelations傳回的物件DataRelation集合。

HasVersion使用 屬性來判斷您想要的 是否存在DataRowVersion

另請參閱

適用於

GetParentRow(String, DataRowVersion)

來源:
DataRow.cs
來源:
DataRow.cs
來源:
DataRow.cs

使用 DataRow 的指定 RelationNameDataRelation,取得 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

例外狀況

關聯和資料列不屬於相同資料表。

relationnull

子資料行有多個父代。

資料列不屬於資料表。

資料列沒有要求的 DataRowVersion

範例

下列範例會使用 GetParentRow ,從中DataTable每個 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,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

DataTable也包含屬性所ParentRelations傳回的物件DataRelation集合。

HasVersion使用 屬性來判斷您想要的 是否存在DataRowVersion

適用於