共用方式為


DataTable.ParentRelations 屬性

定義

為這個 DataTable 取得父關聯的集合。

public:
 property System::Data::DataRelationCollection ^ ParentRelations { System::Data::DataRelationCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Data.DataRelationCollection ParentRelations { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableParentRelationsDescr")]
public System.Data.DataRelationCollection ParentRelations { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ParentRelations : System.Data.DataRelationCollection
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableParentRelationsDescr")>]
member this.ParentRelations : System.Data.DataRelationCollection
Public ReadOnly Property ParentRelations As DataRelationCollection

屬性值

DataRelationCollection,其中包含資料表的父關聯。 如果沒有任何 DataRelation 物件存在,則會傳回空的集合。

屬性

範例

下列範例會 ParentRelations 使用 屬性傳回 中的每個父 DataRelationDataTable。 然後,每個關聯都會當做 的方法中的GetParentRowsDataRow自變數使用,以傳回數據列陣列。 接著會列印數據列中每個數據行的值。

private void GetChildRowsFromDataRelation(DataTable table)
{
    DataRow[] rowArray;
    foreach(DataRelation relation in table.ParentRelations)
    {
        foreach(DataRow row in table.Rows)
        {
            rowArray = row.GetParentRows(relation);
            // Print values of rows.
            for(int i = 0; i < rowArray.Length; i++)
            {
                foreach(DataColumn column in table.Columns)
                {
                    Console.WriteLine(rowArray[i][column]);
                }
            }
        }
    }
}
Private Sub GetChildRowsFromDataRelation(table As DataTable)
    Dim rowArray() As DataRow
    Dim relation As DataRelation, row As DataRow
    Dim column As DataColumn, i As Integer     
    For Each relation In  table.ParentRelations
        For Each row In  table.Rows
            rowArray = row.GetParentRows(relation)
            ' Print values of rows.             
            For i = 0 To rowArray.Length - 1                 
                For Each column In  table.Columns
                    Console.WriteLine(rowArray(i)(column))
                Next column
            Next i
        Next row
    Next relation
End Sub

適用於

另請參閱