共用方式為


DataSet.Relations 屬性

定義

取得關聯的集合,這些關聯會連結資料表,並允許從父資料表巡覽至子資料表。

public:
 property System::Data::DataRelationCollection ^ Relations { System::Data::DataRelationCollection ^ get(); };
public System.Data.DataRelationCollection Relations { get; }
[System.Data.DataSysDescription("DataSetRelationsDescr")]
public System.Data.DataRelationCollection Relations { get; }
member this.Relations : System.Data.DataRelationCollection
[<System.Data.DataSysDescription("DataSetRelationsDescr")>]
member this.Relations : System.Data.DataRelationCollection
Public ReadOnly Property Relations As DataRelationCollection

屬性值

包含 DataRelationCollection 物件集合的 DataRelation。 如果沒有任何 DataRelation 物件存在,則會傳回空的集合。

屬性

範例

下列範例會透過 Relations 屬性列印所有子數據表的數據行名稱。

Private Sub PrintChildRelationRows()
   ' Declare variable to hold the row values.
   Dim rowValues As String
   Dim dataSet As DataSet

   ' Get the DataSet of a DataGrid that is displaying data 
   ' of at least two tables.
   Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)

   ' Navigate using the Relations.
   Dim relation As DataRelation
   Dim row As DataRow
   Dim column As DataColumn

   ' Print the names of each column in each table.
   For Each relation In dataSet.Relations
      For Each column in relation.ChildTable.Columns
          rowValues &= column.ColumnName & " "
      Next
    Next

    ' Display results.
    Console.WriteLine(rowValues)
   End Sub

適用於

另請參閱