asp.net.ph

ConstraintCollection.Add Method ( Constraint )

System.Data Namespace   ConstraintCollection Class


Adds the specified constraint to the collection.

[ VB ]
Overloads Public Sub Add ( _
   ByVal constraint As Constraint _
)

[ C# ]
public void Add (
   Constraint constraint
);

[ C++ ]
public: void Add (
   Constraint* constraint
);

[ JScript ]
public function Add (
   constraint : Constraint
);

Parameters

constraint
The Constraint to add.

Exceptions


Exception Type Condition
ArgumentNullException Occurs when the constraint argument is null.
ArgumentException Occurs when the constraint already belongs to this collection, or belongs to another collection.
DuplicateNameException Occurs when the collection already has a constraint with the same name. The comparison is not case-sensitive.

Remarks

If the collection is successfully changed by adding or removing constraints, the CollectionChanged event occurs.

Example

The following example adds a UniqueConstraint to the ConstraintCollection of a DataTable.

private void AddConstraint ( DataTable myTable ) {
   UniqueConstraint myUniqueConstraint;
   // assuming a column named "UniqueColumn" exists, and its Unique property is true.
   myUniqueConstraint = new UniqueConstraint ( myTable.Columns [ "UniqueColumn" ] );
   myTable.Constraints.Add ( myUniqueConstraint );
}
  C# VB

See Also

ConstraintCollection Members   ConstraintCollection.Add Overload List   UniqueConstraint   ForeignKeyConstraint Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph