asp.net.ph

ConstraintCollection.Add Method ( String, DataColumn [ ], Boolean )

System.Data Namespace   ConstraintCollection Class


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

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

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

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

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

Parameters

name
The name of the UniqueConstraint.
columns
An array of DataColumn objects that are affected by the constraint.
primaryKey
Indicates whether the columns are primary key columns. true if the columns are primary key columns; 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 succesfully.

Example

The following example creates an array of DataColumn objects that are used to create a new UniqueConstraint in a given DataTable.

private void AddUniqueConstraint ( DataTable myTable ) {
   DataColumn [ ] myColumns = new DataColumn [1];
   myColumns [0] = myTable.Columns ["ID"];
   myColumns [1] = myTable.Columns ["Name"];
   myTable.Constraints.Add ( "idNameConstraint", myColumns, 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