DataRow.GetChildRows 方法

定義

取得 DataRow 的子資料列。

多載

GetChildRows(DataRelation)

使用指定的 DataRow,取得這個 DataRelation 的子資料列。

GetChildRows(String)

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

GetChildRows(DataRelation, DataRowVersion)

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

GetChildRows(String, DataRowVersion)

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

GetChildRows(DataRelation)

使用指定的 DataRow,取得這個 DataRelation 的子資料列。

public:
 cli::array <System::Data::DataRow ^> ^ GetChildRows(System::Data::DataRelation ^ relation);
public System.Data.DataRow[] GetChildRows (System.Data.DataRelation? relation);
public System.Data.DataRow[] GetChildRows (System.Data.DataRelation relation);
member this.GetChildRows : System.Data.DataRelation -> System.Data.DataRow[]
Public Function GetChildRows (relation As DataRelation) As DataRow()

參數

relation
DataRelation

要使用的 DataRelation

傳回

DataRow 物件的陣列,或是長度為零的陣列。

例外狀況

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

relation 為 null

資料列不屬於資料表。

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

範例

下列範例會使用 傳 GetChildRows 回 中每個子系的 DataTableDataRowDataRelation 物件。 然後列印資料列中的每個資料行值。

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]);
                }
            }
        }
    }
}
Private Sub GetChildRowsFromDataRelation(table As DataTable)
    Dim relation As DataRelation
    Dim arrRows() As DataRow
    Dim row As DataRow
    Dim i As Integer
    Dim column As DataColumn 
 
    For Each relation In table.ChildRelations
      For Each row In table.Rows
          arrRows = row.GetChildRows(relation)
          ' Print values of rows.
          For i = 0 To arrRows.GetUpperBound(0)
             For Each column in table.Columns
                Console.WriteLine(arrRows(i)(column))
             Next column
          Next i
       Next row
    Next relation
 End Sub

備註

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

另請參閱

適用於

GetChildRows(String)

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

public:
 cli::array <System::Data::DataRow ^> ^ GetChildRows(System::String ^ relationName);
public System.Data.DataRow[] GetChildRows (string? relationName);
public System.Data.DataRow[] GetChildRows (string relationName);
member this.GetChildRows : string -> System.Data.DataRow[]
Public Function GetChildRows (relationName As String) As DataRow()

參數

relationName
String

要使用的 RelationNameDataRelation

傳回

DataRow 物件的陣列,或是長度為零的陣列。

例外狀況

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

資料列不屬於資料表。

備註

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

適用於

GetChildRows(DataRelation, DataRowVersion)

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

public:
 cli::array <System::Data::DataRow ^> ^ GetChildRows(System::Data::DataRelation ^ relation, System::Data::DataRowVersion version);
public System.Data.DataRow[] GetChildRows (System.Data.DataRelation? relation, System.Data.DataRowVersion version);
public System.Data.DataRow[] GetChildRows (System.Data.DataRelation relation, System.Data.DataRowVersion version);
member this.GetChildRows : System.Data.DataRelation * System.Data.DataRowVersion -> System.Data.DataRow[]
Public Function GetChildRows (relation As DataRelation, version As DataRowVersion) As DataRow()

參數

relation
DataRelation

要使用的 DataRelation

version
DataRowVersion

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

傳回

DataRow 物件的陣列。

例外狀況

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

relationnull

資料列不屬於資料表。

資料列沒有要求的 DataRowVersion

範例

下列範例會使用 傳 GetChildRows 回 中每個子系的 DataTableDataRowDataRelation 物件。 然後列印資料列中具有指定版本之每一欄的值。

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]);
                }
            }
        }
    }
}
Private Sub GetChildRowsFromDataRelation(table As DataTable)
    Dim relation As DataRelation
    Dim arrRows() As DataRow
    Dim row As DataRow
    Dim i As Integer
    Dim column As DataColumn 
 
    For Each relation In table.ChildRelations
      For Each row In table.Rows
          arrRows = row.GetChildRows(relation, _
                DataRowVersion.Proposed)
          ' Print values of rows.
          For i = 0 To arrRows.GetUpperBound(0)
             For Each column in table.Columns
                Console.WriteLine(arrRows(i)(column))
             Next column
          Next i
       Next row
    Next relation
End Sub

備註

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

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

如果 Default 指定 ,則所使用的版本取決於 RowState 所叫用之資料列 GetChildRows 的 。 如果叫用的資料 GetChildRows 列具有 ModifiedRowState 、 或 Unchanged 的 , NewCurrent 資料列的版本會用於擷取其目前版本中具有相符值的相關子資料列。 如果叫用 的資料列具有 RowStateDeleted ,則 Original 資料列 GetChildRows 的版本會用於擷取原始版本中具有相符值的相關子資料列。

另請參閱

適用於

GetChildRows(String, DataRowVersion)

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

public:
 cli::array <System::Data::DataRow ^> ^ GetChildRows(System::String ^ relationName, System::Data::DataRowVersion version);
public System.Data.DataRow[] GetChildRows (string? relationName, System.Data.DataRowVersion version);
public System.Data.DataRow[] GetChildRows (string relationName, System.Data.DataRowVersion version);
member this.GetChildRows : string * System.Data.DataRowVersion -> System.Data.DataRow[]
Public Function GetChildRows (relationName As String, version As DataRowVersion) As DataRow()

參數

relationName
String

要使用的 RelationNameDataRelation

version
DataRowVersion

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

傳回

DataRow 物件的陣列,或是長度為零的陣列。

例外狀況

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

relationnull

資料列不屬於資料表。

資料列沒有要求的 DataRowVersion

備註

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

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

如果 Default 指定 ,則所使用的版本取決於 RowState 所叫用之資料列 GetChildRows 的 。 如果叫用的資料 GetChildRows 列具有 ModifiedRowState 、 或 Unchanged 的 , NewCurrent 資料列的版本會用於擷取其目前版本中具有相符值的相關子資料列。 如果叫用 的資料列具有 RowStateDeleted ,則 Original 資料列 GetChildRows 的版本會用於擷取原始版本中具有相符值的相關子資料列。

適用於