asp.net.ph

DataRelation Class

System.Data Namespace


Represents a parent/child relationship between two DataTable objects.

DataRelation Class Members

Collapse   Constructors

Visibility Constructor Parameters
public DataRelation ( String relationName , DataColumn parentColumn , DataColumn childColumn )
public DataRelation ( String relationName , DataColumn parentColumn , DataColumn childColumn , Boolean createConstraints )
public DataRelation ( String relationName , DataColumn parentColumns , DataColumn childColumns )
public DataRelation ( String relationName , DataColumn parentColumns , DataColumn childColumns , Boolean createConstraints )
public DataRelation ( String relationName , String parentTableName , String childTableName , String parentColumnNames , String childColumnNames , Boolean nested )
public DataRelation ( String relationName , String parentTableName , String parentTableNamespace , String childTableName , String childTableNamespace , String parentColumnNames , String childColumnNames , Boolean nested )

Collapse   Properties

Visibility Name Value Type Accessibility
public ChildColumns DataColumn [ Get ]
public ChildKeyConstraint ForeignKeyConstraint [ Get ]
public ChildTable DataTable [ Get ]
public DataSet DataSet [ Get ]
public ExtendedProperties PropertyCollection [ Get ]
public Nested Boolean [ Get , Set ]
public ParentColumns DataColumn [ Get ]
public ParentKeyConstraint UniqueConstraint [ Get ]
public ParentTable DataTable [ Get ]
public RelationName String [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
protected CheckStateForProperty ( ) Void
public ToString ( ) String

Remarks

A DataRelation is used to relate two DataTable objects to each other through 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 DataType value for both columns must be identical.

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

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

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

Example

The following example initializes a new DataRelation and adds it to the DataRelationCollection of a DataSet.

DataRelation categoryId = new DataRelation ( "categoryId", 
   myDataSet.Tables [ "Categories" ].Columns [ "CategoryID" ],
   myDataSet.Tables [ "Products" ].Columns [ "CategoryID" ] );

   // add the relation to the DataSet.
   myDataSet.Relations.Add ( categoryId );
  C# VB

 Show me 

See Also

ChildRelations   DataColumn   DataSet   ForeignKeyConstraint   DataRelationCollection   UniqueConstraint   ParentRelations Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph