DataRow.GetChildRows 方法

定义

获取 DataRow 的子行。

重载

GetChildRows(DataRelation)

使用指定的 DataRelation 获取此 DataRow 的子行。

GetChildRows(String)

使用 DataRelation 的指定 RelationName 获取 DataRow 的子行。

GetChildRows(DataRelation, DataRowVersion)

使用指定的 DataRelationDataRowVersion 获取 DataRow 的子行。

GetChildRows(String, DataRowVersion)

使用 DataRelation 的指定 RelationNameDataRowVersion获取 DataRow 的子行。

GetChildRows(DataRelation)

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

使用指定的 DataRelation 获取此 DataRow 的子行。

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

参数

relation
DataRelation

要使用的 DataRelation

返回

一个 DataRow 对象数组,或长度为零的数组。

例外

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

关系为 null

此行不属于该表。

该行没有此版本的数据。

示例

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

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

注解

DataTable还包含 由 ChildRelations 属性返回的 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

GetChildRows(String)

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

使用 DataRelation 的指定 RelationName 获取 DataRow 的子行。

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

参数

relationName
String

要使用的 DataRelationRelationName

返回

一个 DataRow 对象数组,或长度为零的数组。

例外

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

此行不属于该表。

注解

DataTable还包含 由 ChildRelations 属性返回的 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

GetChildRows(DataRelation, DataRowVersion)

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

使用指定的 DataRelationDataRowVersion 获取 DataRow 的子行。

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

参数

relation
DataRelation

要使用的 DataRelation

version
DataRowVersion

DataRowVersion 值之一,指定要获取的数据的版本。 可能值为 DefaultOriginalCurrentProposed

返回

一个 DataRow 对象数组。

例外

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

relationnull

此行不属于该表。

该行没有请求的 DataRowVersion

示例

以下示例使用 GetChildRows 返回 中每个子DataRow项的DataTableDataRelation对象。 然后打印行中具有指定版本的每列的值。

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

注解

DataTable还包含 由 ChildRelations 属性返回的 DataRelation 对象的集合。

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

如果 Default 指定 ,则使用的版本取决于 RowState 所调用的行 GetChildRows 的 。 如果调用的GetChildRows行具有 、 或 Unchanged的 , NewRowStateModifiedCurrent该行的版本用于提取具有当前版本中匹配值的相关子行。 如果对其调用的GetChildRows行具有 的 DeletedRowStateOriginal该行的版本用于提取具有原始版本中匹配值的相关子行。

另请参阅

适用于

.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

GetChildRows(String, DataRowVersion)

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

使用 DataRelation 的指定 RelationNameDataRowVersion获取 DataRow 的子行。

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

参数

relationName
String

要使用的 DataRelationRelationName

version
DataRowVersion

DataRowVersion 值之一,指定要获取的数据的版本。 可能值为 DefaultOriginalCurrentProposed

返回

一个 DataRow 对象数组,或长度为零的数组。

例外

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

relationnull

此行不属于该表。

该行没有请求的 DataRowVersion

注解

DataTable还包含 由 ChildRelations 属性返回的 DataRelation 对象的集合。

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

如果 Default 指定 ,则使用的版本取决于 RowState 所调用的行 GetChildRows 的 。 如果调用的GetChildRows行具有 、 或 Unchanged的 , NewRowStateModifiedCurrent该行的版本用于提取具有当前版本中匹配值的相关子行。 如果对其调用的GetChildRows行具有 的 DeletedRowStateOriginal该行的版本用于提取具有原始版本中匹配值的相关子行。

适用于

.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