System.Data.ConstraintCollection Class

Represents a collection of constraints for a System.Data.DataTable.

See Also: ConstraintCollection Members

Syntax

[System.ComponentModel.Editor("Microsoft.VSDesigner.Data.Design.ConstraintsCollectionEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.DefaultEvent("CollectionChanged")]
public sealed class ConstraintCollection : InternalDataCollectionBase

Remarks

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.

Note:

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.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0