DataRow.GetParentRows 方法

定義

取得 DataRow 的父資料列。Gets the parent rows of a DataRow.

多載

GetParentRows(DataRelation, DataRowVersion)

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

GetParentRows(DataRelation)

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

GetParentRows(String)

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

GetParentRows(String, DataRowVersion)

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

GetParentRows(DataRelation, DataRowVersion)

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

public:
 cli::array <System::Data::DataRow ^> ^ GetParentRows(System::Data::DataRelation ^ relation, System::Data::DataRowVersion version);
public System.Data.DataRow[] GetParentRows (System.Data.DataRelation relation, System.Data.DataRowVersion version);
member this.GetParentRows : System.Data.DataRelation * System.Data.DataRowVersion -> System.Data.DataRow[]
Public Function GetParentRows (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.

傳回

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

例外狀況

DataRelation 不屬於這個資料列的 DataSetThe DataRelation does not belong to this row's DataSet.

資料列為 nullThe row is null.

關聯的子資料表不是資料列所屬的資料表。The relation's child table is not the table the row belongs to.

資料列不屬於 DataTableThe row does not belong to a DataTable.

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

範例

下列範例會使用 GetParentRows,針對 DataTable中的每個子 DataRelation 傳回子 DataRow 物件。The following example uses the GetParentRows 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 Sub GetChildRowsFromDataRelation(table As DataTable, ver As DataRowVersion)
    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.ParentRelations
      For Each row In table.Rows
          arrRows = row.GetParentRows(relation, ver)
          ' Print values of rows.
          For i = 0 To arrRows.GetUpperBound(0)
             For Each column in table.Columns
                Console.WriteLine(arrRows(i)(column.ColumnName))
             Next column
          Next i
       Next row
    Next relation
End Sub

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

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

另請參閱

GetParentRows(DataRelation)

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

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

參數

relation
DataRelation

要使用的 DataRelationThe DataRelation to use.

傳回

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

例外狀況

DataRelation 不屬於這個資料列的 DataSetThe DataRelation does not belong to this row's DataSet.

資料列為 nullThe row is null.

關聯的子資料表不是資料列所屬的資料表。The relation's child table is not the table the row belongs to.

資料列不屬於 DataTableThe row does not belong to a DataTable.

範例

下列範例會使用 GetParentRows,針對 DataTable中的每個子 DataRelation 傳回子 DataRow 物件。The following example uses the GetParentRows 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 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.ParentRelations
      For Each row In table.Rows
          arrRows = row.GetParentRows(relation)
          ' Print values of rows.
          For i = 0 To arrRows.GetUpperBound(0)
             For Each column in table.Columns
                Console.WriteLine(arrRows(i)(column.ColumnName))
             Next column
          Next i
       Next row
    Next relation
 End Sub

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

另請參閱

GetParentRows(String)

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

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

參數

傳回

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.

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

GetParentRows(String, DataRowVersion)

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

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

參數

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.

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

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

適用於