DataRow.GetChildRows 方法

定義

取得 DataRow 的子資料列。Gets the child rows of a DataRow.

多載

GetChildRows(DataRelation)

使用指定的 DataRow,取得這個 DataRelation 的子資料列。Gets the child rows of this DataRow using the specified DataRelation.

GetChildRows(String)

使用 DataRow 的指定 RelationName,取得 DataRelation 的子資料列。Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

GetChildRows(DataRelation, DataRowVersion)

使用指定的 DataRowDataRelation,取得 DataRowVersion 的子資料列。Gets the child rows of a DataRow using the specified DataRelation, and DataRowVersion.

GetChildRows(String, DataRowVersion)

使用 DataRow 的指定 RelationNameDataRelation,取得 DataRowVersion 的子資料列。Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetChildRows(DataRelation)

使用指定的 DataRow,取得這個 DataRelation 的子資料列。Gets the child rows of this DataRow using the specified DataRelation.

public:
 cli::array <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

要使用的 DataRelationThe DataRelation to use.

傳回

DataRow 物件的陣列,或是長度為零的陣列。An array of DataRow objects or an array of length zero.

例外狀況

關聯和資料列不屬於相同資料表。The relation and row do not belong to the same table.

relation 為 nullThe relation is null.

資料列不屬於資料表。The row does not belong to the table.

資料列沒有這個版本的資料。The row does not have this version of data.

範例

下列範例GetChildRows會使用來傳回中DataTable每個子DataRow DataRelation系的子物件。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.

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

備註

也包含ChildRelations屬性所傳回的DataRelation物件集合。 DataTableThe DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

另請參閱

GetChildRows(String)

使用 DataRow 的指定 RelationName,取得 DataRelation 的子資料列。Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

public:
 cli::array <System::Data::DataRow ^> ^ GetChildRows(System::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

要使用的 RelationNameDataRelationThe RelationName of the DataRelation to use.

傳回

DataRow 物件的陣列,或是長度為零的陣列。An array of DataRow objects or an array of length zero.

例外狀況

關聯和資料列不屬於相同資料表。The relation and row do not belong to the same table.

資料列不屬於資料表。The row does not belong to the table.

備註

也包含ChildRelations屬性所傳回的DataRelation物件集合。 DataTableThe DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

GetChildRows(DataRelation, DataRowVersion)

使用指定的 DataRowDataRelation,取得 DataRowVersion 的子資料列。Gets the child rows of a DataRow using the specified DataRelation, and 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);
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

要使用的 DataRelationThe DataRelation to use.

version
DataRowVersion

其中一個 DataRowVersion 值,指定要取得的資料版本。One of the DataRowVersion values specifying the version of the data to get. 可能的值為 DefaultOriginalCurrentProposedPossible values are Default, Original, Current, and Proposed.

傳回

DataRow 物件的陣列。An array of DataRow objects.

例外狀況

關聯和資料列不屬於相同資料表。The relation and row do not belong to the same table.

relationnullThe relation is null.

資料列不屬於資料表。The row does not belong to the table.

資料列沒有要求的 DataRowVersionThe row does not have the requested DataRowVersion.

範例

下列範例GetChildRows會使用來傳回中DataTable每個子DataRow DataRelation系的子物件。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.

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

備註

也包含ChildRelations屬性所傳回的DataRelation物件集合。 DataTableThe DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

使用屬性來判斷您想要DataRowVersion的是否存在。 HasVersionUse the HasVersion property to determine whether the DataRowVersion that you want exists.

如果Default指定了, 則使用的版本取決於RowState叫用之GetChildRows資料列的。If Default is specified, the version that is used depends on the RowState of the row on which GetChildRows is invoked. 如果叫GetChildRows用的資料列RowState具有、 NewUnchangedModified, 則會使用該Current資料列的版本來提取其目前版本中具有相符值的相關子資料列。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. 如果叫用的資料GetChildRowsRowState具有的Deleted, 則會使用Original該資料列的版本來提取其原始版本中具有相符值的相關子資料列。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.

另請參閱

GetChildRows(String, DataRowVersion)

使用 DataRow 的指定 RelationNameDataRelation,取得 DataRowVersion 的子資料列。Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and 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);
member this.GetChildRows : string * System.Data.DataRowVersion -> System.Data.DataRow[]
Public Function GetChildRows (relationName As String, version As DataRowVersion) As DataRow()

參數

relationName
String

要使用的 RelationNameDataRelationThe RelationName of the DataRelation to use.

version
DataRowVersion

其中一個 DataRowVersion 值,指定要取得的資料版本。One of the DataRowVersion values specifying the version of the data to get. 可能的值為 DefaultOriginalCurrentProposedPossible values are Default, Original, Current, and Proposed.

傳回

DataRow 物件的陣列,或是長度為零的陣列。An array of DataRow objects or an array of length zero.

例外狀況

關聯和資料列不屬於相同資料表。The relation and row do not belong to the same table.

relationnullThe relation is null.

資料列不屬於資料表。The row does not belong to the table.

資料列沒有要求的 DataRowVersionThe row does not have the requested DataRowVersion.

備註

也包含ChildRelations屬性所傳回的DataRelation物件集合。 DataTableThe DataTable also contains a collection of DataRelation objects that is returned by the ChildRelations property.

使用屬性來判斷您想要DataRowVersion的是否存在。 HasVersionUse the HasVersion property to determine whether the DataRowVersion that you want exists.

如果Default指定了, 則使用的版本取決於RowState叫用之GetChildRows資料列的。If Default is specified, the version that is used depends on the RowState of the row on which GetChildRows is invoked. 如果叫GetChildRows用的資料列RowState具有、 NewUnchangedModified, 則會使用該Current資料列的版本來提取其目前版本中具有相符值的相關子資料列。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. 如果叫用的資料GetChildRowsRowState具有的Deleted, 則會使用Original該資料列的版本來提取其原始版本中具有相符值的相關子資料列。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.

適用於