Gets the collection of constraints maintained by this table.
[Visual Basic] Public ReadOnly Property Constraints As ConstraintsCollection [C#] public ConstraintsCollection Constraints {get;} [C++] public: __property ConstraintsCollection* get_Constraints(); [JScript] public function get Constraints() : ConstraintsCollection;
A ConstraintsCollection that contains the collection of Constraint objects for the table.
A ForeignKeyConstraint restricts the action performed when a value in a column (or columns) is either deleted or updated. Such a constraint is intended to be used with primary key columns. In a parent/child relationship between two tables, deleting a value from the parent table can affect the child rows in one of the following ways.
A UniqueConstraint becomes active when attempting to set a value in a primary key to a non-unique value.
The following example adds a ForeignKeyConstraint to the collection of constraints.
[Visual Basic]
' The next line goes into the Declarations section of the module: ' SuppliersProducts is a class derived from DataSet. Private myDataSet As SuppliersProducts Private Sub CreateConstraint() Dim myFKC As ForeignKeyConstraint myFKC = New ForeignKeyConstraint _ (myDataSet.Tables("Suppliers"), _ myDataSet.Tables("Suppliers").Columns("CompanyID"), _ myDataSet.Tables("Products"), _ myDataSet.Tables("Products").Columns("CompanyID")) ' Set null values when a value is deleted. myFKC.DeleteRule = Rule.SetNull myFKC.UpdateRule = Rule.Cascade myFKC.AcceptRejectRule = AcceptRejectRule.Cascade myDataSet.Tables("Suppliers").Constraints.Add myFKC myDataSet.EnforceConstraints = True End Sub
DataTable Class | DataTable Members | System.Data Namespace | AcceptRejectRule | ForeignKeyConstraint | UniqueConstraint | Rule