Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Relations Property

DataSet.Relations Property

Get the collection of relations that link tables and allow navigation from parent tables to child tables.

[Visual Basic]
Public ReadOnly Property Relations As DataRelationCollection
[C#]
public DataRelationCollection Relations {get;}
[C++]
public: __property DataRelationCollection* get_Relations();
[JScript]
public function get Relations() : DataRelationCollection;

Property Value

A DataRelationCollection that contains a collection of DataRelation objects; otherwise a null value if no DataRelation objects exist.

Example

[Visual Basic] The following example prints the column name of all child tables through the Relations property.

[Visual Basic] 
Private Sub PrintChildRelationRows()
   ' Declare variable to hold the row values.
   Dim strRowVals As String
   Dim myDataSet As DataSet
   ' Get the DataSet of a DataGrid that is displaying data of at least two
   ' tables.
   Dim myTable As DataTable = CType(DataGrid1.DataSource, DataTable)
   ' Navigate using the Relations.
   Dim myRel As DataRelation
   Dim row As DataRow
   Dim col As DataColumn
   ' Print the names of each column in each table through the Relations.
   For Each myRel In myDataSet.Relations
      For Each col in myRel.ChildTable.Columns
          strRowVals &= col.ColumnName & " "
      Next
    Next
    ' Display results.
    Console.WriteLine(strRowVals)
   End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataSet Class | DataSet Members | System.Data Namespace | DataRelation | DataTable | DataRelationCollection

Show:
© 2015 Microsoft