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
- 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.
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 succesfully.
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 );
}
Private Sub AddUniqueConstraint ( myTable As DataTable )
Dim myColumns ( 1 ) As DataColumn
myColumns ( 0 ) = myTable.Columns ( "ID" )
myColumns ( 1 ) = myTable.Columns ( "Name" )
myTable.Constraints.Add ( "idNameConstraint", myColumns, True )
End Sub |
|
C# |
VB |
ConstraintCollection Members ConstraintCollection.Add Overload List UniqueConstraint