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 的父資料列。

C#
public System.Data.DataRow? GetParentRow (System.Data.DataRelation? relation);
C#
public System.Data.DataRow GetParentRow (System.Data.DataRelation relation);

參數

relation
DataRelation

要使用的 DataRelation

傳回

目前資料列的父 DataRow

例外狀況

relation 不屬於 DataTable

-或-

資料列為 null

子資料行有多個父代。

這個資料列不屬於 DataRelation 物件的子資料表。

資料列不屬於資料表。

範例

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

C#
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);
}

備註

在 中DataSet,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

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

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetParentRow(String)

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

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

C#
public System.Data.DataRow? GetParentRow (string? relationName);
C#
public System.Data.DataRow GetParentRow (string relationName);

參數

relationName
String

RelationNameDataRelation

傳回

目前資料列的父 DataRow

例外狀況

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

子資料行有多個父代。

資料列不屬於資料表。

範例

下列範例會使用 GetParentRow ,從中DataTable每個 DataRow 的父數據列列印值。

C#
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);
}

備註

在 中DataSet,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

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

適用於

.NET 9 和其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetParentRow(DataRelation, DataRowVersion)

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

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

C#
public System.Data.DataRow? GetParentRow (System.Data.DataRelation? relation, System.Data.DataRowVersion version);
C#
public System.Data.DataRow GetParentRow (System.Data.DataRelation relation, System.Data.DataRowVersion version);

參數

relation
DataRelation

要使用的 DataRelation

version
DataRowVersion

其中一個 DataRowVersion 值,指定要取得的資料版本。

傳回

目前資料列的父 DataRow

例外狀況

資料列為 null

-或-

relation 不屬於這個資料表的父關聯。

子資料行有多個父代。

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

資料列不屬於資料表。

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

範例

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

C#
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);
}

備註

在 中DataSet,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

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

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

另請參閱

適用於

.NET 9 和其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

GetParentRow(String, DataRowVersion)

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

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

C#
public System.Data.DataRow? GetParentRow (string? relationName, System.Data.DataRowVersion version);
C#
public System.Data.DataRow GetParentRow (string relationName, System.Data.DataRowVersion version);

參數

relationName
String

RelationNameDataRelation

version
DataRowVersion

其中一個 DataRowVersion 值。

傳回

目前資料列的父 DataRow

例外狀況

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

relationnull

子資料行有多個父代。

資料列不屬於資料表。

資料列沒有要求的 DataRowVersion

範例

下列範例會使用 GetParentRow ,從中DataTable每個 DataRow 的父數據列列印值。

C#
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);
}

備註

在 中DataSet,方法會傳GetParentRows回數據集的所有父DataRelation物件集合。

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

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

適用於

.NET 9 和其他版本
產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1