System.Data.DataRelation Class

Represents a parent/child relationship between two System.Data.DataTable objects.

See Also: DataRelation Members

Syntax

[System.ComponentModel.TypeConverter(typeof(System.Data.RelationshipConverter))]
[System.ComponentModel.DefaultProperty("RelationName")]
[System.ComponentModel.Editor("Microsoft.VSDesigner.Data.Design.DataRelationEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class DataRelation

Remarks

A System.Data.DataRelation is used to relate two System.Data.DataTable objects to each other through System.Data.DataColumn objects. For example, in a Customer/Orders relationship, the Customers table is the parent and the Orders table is the child of the relationship. This is similar to a primary key/foreign key relationship. For more information, see Navigating a Relationship between Tables.

Relationships are created between matching columns in the parent and child tables. That is, the DataColumn.DataType value for both columns must be identical.

Relationships can also cascade various changes from the parent System.Data.DataRow to its child rows. To control how values are changed in child rows, add a System.Data.ForeignKeyConstraint to the System.Data.ConstraintCollection of the System.Data.DataTable object. The System.Data.ConstraintCollection determines what action to take when a value in a parent table is deleted or updated.

When a System.Data.DataRelation is created, it first verifies that the relationship can be established. After it is added to the System.Data.DataRelationCollection, the relationship is maintained by disallowing any changes that would invalidate it. Between the period when a System.Data.DataRelation is created and added to the System.Data.DataRelationCollection, it is possible for additional changes to be made to the parent or child rows. An exception is generated if this causes a relationship that is no longer valid.

Note:

Data corruption can occur if a bi-directional relation is defined between two tables. A bi-directional relation consists of two DataRelation objects that use the same columns, with the parent-child roles switched. No exception is raised when the DataRelation objects are saved; however, data corruption can occur.

System.Data.DataRelation objects are contained in a System.Data.DataRelationCollection, which you can access through the DataSet.Relations property of the System.Data.DataSet, and the DataTable.ChildRelations and DataTable.ParentRelations properties of the System.Data.DataTable.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0