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 DataRelations (ADO.NET).
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
Open your dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.
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.
Select the parent table from the Parent Table box. The parent table contains records on the "one" side of a one-to-many relationship.
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.
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.
Select the columns that join the tables in the Key Columns and Foreign Key Columns lists.
Select whether to create a relation, constraint, or both. For information, see Introduction to DataRelation Objects.
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 Nesting DataRelations (ADO.NET).
Set the rules to be enforced when making changes to records in these tables. For more information, see Rule.
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.