16 March 2012

Adding DataRelations between Datatables in c#

Adding DataRelations between Datatables in c#



In a DataSet with multiple DataTable objects, you can use DataRelation objects to relate one table to another, to navigate through the tables, and to return child or parent rows from a related table.

Adding a DataRelation to a DataSet adds, by default, a UniqueConstraint to the parent table and a ForeignKeyConstraintto the child table. For more information about these default constraints, see DataTable Constraints (ADO.NET).


The following code example creates a DataRelation using two DataTable objects in a DataSet. Each DataTable contains a column named CustID, which serves as a link between the two DataTable objects. The example adds a singleDataRelation to the Relations collection of the DataSet. The first argument in the example specifies the name of theDataRelation being created. The second argument sets the parent DataColumn and the third argument sets the childDataColumn.

customerOrders.Relations.Add("CustOrders",
customerOrders.Tables["Customers"].Columns["CustID"],
customerOrders.Tables["Orders"].Columns["CustID"]);




No comments:

Post a Comment

Comments Welcome

Consistency level in Azure cosmos db

 Consistency level in Azure cosmos db Azure Cosmos DB offers five well-defined consistency levels to provide developers with the flexibility...