Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


DataRow.GetParentRow Method

Definition

Gets the parent row of a DataRow.

Overloads

GetParentRow(DataRelation)

Gets the parent row of a DataRow using the specified DataRelation.

GetParentRow(String)

Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

GetParentRow(DataRelation, DataRowVersion)

Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

GetParentRow(String, DataRowVersion)

Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetParentRow(DataRelation)

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

Gets the parent row of a DataRow using the specified DataRelation.

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

Parameters

relation
DataRelation

The DataRelation to use.

Returns

The parent DataRow of the current row.

Exceptions

The relation does not belong to the DataTable.

-or-

The row is null.

A child row has multiple parents.

This row does not belong to the child table of the DataRelation object.

The row does not belong to a table.

Examples

The 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.

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

Remarks

In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

See also

Applies to

.NET 10 és más verziók
Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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)

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

Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

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

Parameters

relationName
String

The RelationName of a DataRelation.

Returns

The parent DataRow of the current row.

Exceptions

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.

Examples

The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.

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

Remarks

In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

Applies to

.NET 10 és más verziók
Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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)

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

Gets the parent row of a DataRow using the specified DataRelation, and 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);

Parameters

relation
DataRelation

The DataRelation to use.

version
DataRowVersion

One of the DataRowVersion values specifying the version of the data to get.

Returns

The parent DataRow of the current row.

Exceptions

The row is null.

-or-

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.

Examples

The 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.

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

Remarks

In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

Use the HasVersion property to determine whether the DataRowVersion that you want exists.

See also

Applies to

.NET 10 és más verziók
Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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)

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

Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and 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);

Parameters

relationName
String

The RelationName of a DataRelation.

version
DataRowVersion

One of the DataRowVersion values.

Returns

The parent DataRow of the current row.

Exceptions

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.

The row does not have the requested DataRowVersion.

Examples

The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.

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

Remarks

In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

Use the HasVersion property to determine whether the DataRowVersion that you want exists.

Applies to

.NET 10 és más verziók
Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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