DataRow.GetChildRows Method

Definition

Gets the child rows of a DataRow.

Overloads

GetChildRows(DataRelation)

Gets the child rows of this DataRow using the specified DataRelation.

GetChildRows(String)

Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

GetChildRows(DataRelation, DataRowVersion)

Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

GetChildRows(String, DataRowVersion)

Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetChildRows(DataRelation)

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

Gets the child rows of this DataRow using the specified DataRelation.

C#
public System.Data.DataRow[] GetChildRows(System.Data.DataRelation? relation);
C#
public System.Data.DataRow[] GetChildRows(System.Data.DataRelation relation);

Parameters

relation
DataRelation

The DataRelation to use.

Returns

An array of DataRow objects or an array of length zero.

Exceptions

The relation and row do not belong to the same table.

The relation is null.

The row does not belong to the table.

The row does not have this version of data.

Examples

The following example uses the GetChildRows 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 GetChildRowsFromDataRelation(DataTable table)
{
    DataRow[] arrRows;
    foreach(DataRelation relation in table.ChildRelations)
    {
        foreach(DataRow row in table.Rows)
        {
            arrRows = row.GetChildRows(relation);
            // Print values of rows.
            for(int i = 0; i < arrRows.Length; i++)
            {
                foreach(DataColumn column in table.Columns)
                {
                    Console.WriteLine(arrRows[i][column]);
                }
            }
        }
    }
}

Remarks

The DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

See also

Applies to

.NET 9 and other versions
Product Versions
.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

GetChildRows(String)

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

Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

C#
public System.Data.DataRow[] GetChildRows(string? relationName);
C#
public System.Data.DataRow[] GetChildRows(string relationName);

Parameters

relationName
String

The RelationName of the DataRelation to use.

Returns

An array of DataRow objects or an array of length zero.

Exceptions

The relation and row do not belong to the same table.

The row does not belong to the table.

Remarks

The DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

Applies to

.NET 9 and other versions
Product Versions
.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

GetChildRows(DataRelation, DataRowVersion)

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

Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

C#
public System.Data.DataRow[] GetChildRows(System.Data.DataRelation? relation, System.Data.DataRowVersion version);
C#
public System.Data.DataRow[] GetChildRows(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. Possible values are Default, Original, Current, and Proposed.

Returns

An array of DataRow objects.

Exceptions

The relation and row do not belong to the same table.

The relation is null.

The row does not belong to the table.

The row does not have the requested DataRowVersion.

Examples

The following example uses the GetChildRows to return the child DataRow objects for every child DataRelation in a DataTable. The value of each column with the specified version in the row is then printed.

C#
private void GetChildRowsFromDataRelation(DataTable table )
{
    DataRow[] arrRows;
    foreach(DataRelation relation in table.ChildRelations)
    {
        foreach(DataRow row in table.Rows)
        {
            arrRows = row.GetChildRows(relation,
                DataRowVersion.Proposed);
            // Print values of rows.
            for(int i = 0; i < arrRows.Length; i++)
            {
                foreach(DataColumn column in table.Columns)
                {
                    Console.WriteLine(arrRows[i][column]);
                }
            }
        }
    }
}

Remarks

The DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

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

If Default is specified, the version that is used depends on the RowState of the row on which GetChildRows is invoked. If the row on which GetChildRows is invoked has a RowState of Modified, New, or Unchanged, the Current version of the row is used for fetching related child rows with matching values in their Current versions. If the row on which GetChildRows is invoked has a RowState of Deleted, the Original version of the row is used for fetching related child rows with matching values in their original versions.

See also

Applies to

.NET 9 and other versions
Product Versions
.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

GetChildRows(String, DataRowVersion)

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

Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

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

Parameters

relationName
String

The RelationName of the DataRelation to use.

version
DataRowVersion

One of the DataRowVersion values specifying the version of the data to get. Possible values are Default, Original, Current, and Proposed.

Returns

An array of DataRow objects or an array of length zero.

Exceptions

The relation and row do not belong to the same table.

The row does not belong to the table.

The row does not have the requested DataRowVersion.

Remarks

The DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

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

If Default is specified, the version that is used depends on the RowState of the row on which GetChildRows is invoked. If the row on which GetChildRows is invoked has a RowState of Modified, New, or Unchanged, the Current version of the row is used for fetching related child rows with matching values in their Current versions. If the row on which GetChildRows is invoked has a RowState of Deleted, the Original version of the row is used for fetching related child rows with matching values in their original versions.

Applies to

.NET 9 and other versions
Product Versions
.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