Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

How to: Create DataRelations with the Dataset Designer 

Relationships between data tables use DataRelation objects to connect records that are associated with each other, such as a customer and their orders. When you create data tables with the data design tools in Visual Studio, relationships are created automatically if the information can be gathered from the source of your data. If you manually add data tables from the DataSet tab of the Toolbox, you may have to create the relationship manually as explained on this Help page. For information on creating DataRelation objects programmatically, see Adding a Relationship between Tables.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To create a relationship between two DataTables

  1. Open your dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.

  2. Drag a Relation object from the DataSet toolbox onto the child data table in the relationship.

    The Relation Dialog Box opens, populating the Child Table box with the table you dragged the Relation onto.

  3. Select the parent table from the Parent Table box. The parent table contains records on the "one" side of a one-to-many relationship.

  4. Verify the correct child table is displayed in the Child Table box. The child table contains records on the "many" side of a one-to-many relationship.

  5. Type a name for the relationship in the Name box, or leave the default name based on the selected tables. This is the name of the actual DataRelation object in code.

  6. Select the columns that join the tables in the Key Columns and Foreign Key Columns lists.

  7. Select whether to create a relation, constraint, or both. For information, see Introduction to DataRelation Objects.

  8. Select or clear the Nested Relation box. Selecting this option sets the Nested property to true, and it causes the child rows of the relation to be nested within the parent column when written as XML data or synchronized with an XmlDataDocument. For more information, see Nested DataRelations.

  9. Set the rules to be enforced when making changes to records in these tables. For more information, see Rule.

  10. Click OK to create the relationship; a relation line appears on the designer between the two tables. You can toggle showing the relation name on the design surface by selecting or clearing Show Relation Labels on the Data menu.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.