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
- 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.
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. |
The CollectionChanged event occurs if the constraint is added successfully.
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 );
}
Private Sub AddUniqueConstraint ( myTable As DataTable )
myTable.Constraints.Add ( "idConstraint", myTable.Columns ( "id" ), True )
End Sub |
|
C# |
VB |
ConstraintCollection Members ConstraintCollection.Add Overload List UniqueConstraint