asp.net.ph

ConstraintCollection.Add Method ( String, DataColumn, Boolean )

System.Data Namespace   ConstraintCollection Class


Constructs a new UniqueConstraint, using the specified DataColumn, and adds it to the collection.

[ VB ]
Overridable Overloads Public Function Add ( _
   ByVal name As String, _
   ByVal column As DataColumn, _
   ByVal primaryKey As Boolean _
) As Constraint

[ C# ]
public virtual Constraint Add (
   String name,
   DataColumn column,
   bool primaryKey
);

[ C++ ]
public: virtual Constraint* Add (
   String* name,
   DataColumn* column,
   bool primaryKey
);

[ JScript ]
public function Add (
   name : String,
   column : DataColumn,
   primaryKey : Boolean
) : Constraint

Parameters

name
The name of the UniqueConstraint.
column
The DataColumn affected by the constraint.
primaryKey
Indicates whether the column is a primary key column. true if the column is a primary key column; otherwise, false.

Exceptions


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

Remarks

The CollectionChanged event occurs if the constraint is added successfully.

Example

The following example uses the Add method to create and add a new UniqueConstraint to a ConstraintCollection.

private void AddUniqueConstraint ( DataTable myTable ) {
   myTable.Constraints.Add ( "idConstraint", myTable.Columns ["id"], true );
}
  C# VB

See Also

ConstraintCollection Members   ConstraintCollection.Add Overload List   UniqueConstraint 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