Represents a parent/child relationship between two DataTable objects.
public ref class DataRelation
[System.ComponentModel.TypeConverter(typeof(System.Data.RelationshipConverter))]
public class DataRelation
public class DataRelation
[System.ComponentModel.TypeConverter(typeof(System.Data.RelationshipConverter))]
[System.Serializable]
public class DataRelation
[<System.ComponentModel.TypeConverter(typeof(System.Data.RelationshipConverter))>]
type DataRelation = class
type DataRelation = class
[<System.ComponentModel.TypeConverter(typeof(System.Data.RelationshipConverter))>]
[<System.Serializable>]
type DataRelation = class
Public Class DataRelation
The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.
private void CreateRelation()
{
// Get the DataColumn objects from two DataTable objects
// in a DataSet. Code to get the DataSet not shown here.
DataColumn parentColumn =
DataSet1.Tables["Customers"].Columns["CustID"];
DataColumn childColumn =
DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders",
parentColumn, childColumn);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
}
Private Sub CreateRelation()
' Get the DataColumn objects from two DataTable objects
' in a DataSet. Code to get the DataSet not shown here.
Dim parentColumn As DataColumn = _
DataSet1.Tables("Customers").Columns("CustID")
Dim childColumn As DataColumn = DataSet1.Tables( _
"Orders").Columns("CustID")
' Create DataRelation.
Dim relCustOrder As DataRelation
relCustOrder = New DataRelation( _
"CustomersOrders", parentColumn, childColumn)
' Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder)
End Sub
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 DataRelations.
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 determines 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 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.
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.
Constructors DataRelation(String, DataColumn, DataColumn, Boolean)Initializes a new instance of the DataRelation class using the specified name, parent and child DataColumn objects, and a value that indicates whether to create constraints.
DataRelation(String, DataColumn, DataColumn)Initializes a new instance of the DataRelation class using the specified DataRelation name, and parent and child DataColumn objects.
DataRelation(String, DataColumn[], DataColumn[], Boolean)Initializes a new instance of the DataRelation class using the specified name, matched arrays of parent and child DataColumn objects, and value that indicates whether to create constraints.
DataRelation(String, DataColumn[], DataColumn[])Initializes a new instance of the DataRelation class using the specified DataRelation name and matched arrays of parent and child DataColumn objects.
DataRelation(String, String, String, String, String, String[], String[], Boolean)This constructor is provided for design time support in the Visual Studio environment.
DataRelation(String, String, String, String[], String[], Boolean)This constructor is provided for design time support in the Visual Studio environment.
Properties Methods Thread SafetyThis type is safe for multithreaded read operations. You must synchronize any write operations.
See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4