Represents a collection of constraints for a System.Data.DataTable.
See Also: ConstraintCollection Members
The System.Data.ConstraintCollection is accessed through the DataTable.Constraints property.
The System.Data.ConstraintCollection can contain both System.Data.UniqueConstraint and System.Data.ForeignKeyConstraint objects for the System.Data.DataTable. A System.Data.UniqueConstraint object makes sure that data in a specific column is always unique to preserve the data integrity. The System.Data.ForeignKeyConstraint determines what will occur in related tables when data in the System.Data.DataTable is either updated or deleted. For example, if a row is deleted, the System.Data.ForeignKeyConstraint will determine whether the related rows are also deleted (a cascade), or some other course of action.
When you add a System.Data.DataRelation that creates a relationship between two tables to a System.Data.DataSet, both a System.Data.ForeignKeyConstraint and a System.Data.UniqueConstraint are created automatically. The System.Data.UniqueConstraint is applied to the primary key column in the parent System.Data.DataTable, and the constraint is added to that table's System.Data.ConstraintCollection. The System.Data.ForeignKeyConstraint is applied to the primary key column and the foreign key column, and the constraint is added to the child table's System.Data.ConstraintCollection.
The System.Data.ConstraintCollection uses standard collection methods such as ConstraintCollection.Add(Constraint), ConstraintCollection.Clear, and ConstraintCollection.Remove(Constraint). In addition, the ConstraintCollection.Contains(string) method can be used to look for the existence of a particular constraint in the collection.
A System.Data.UniqueConstraint is created when a System.Data.DataColumn with its DataColumn.Unique property set to true is added to a System.Data.DataTable object's System.Data.DataColumnCollection.
A System.Data.ForeignKeyConstraint is created when a System.Data.DataRelation is added to a System.Data.DataSet object's System.Data.DataRelationCollection.