Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
UniqueConstraint Class
Collapse the table of content
Expand the table of content

UniqueConstraint Class

Represents a restriction on a set of columns in which all values must be unique.

For a list of all members of this type, see UniqueConstraint Members.


[Visual Basic]
Public Class UniqueConstraint
   Inherits Constraint
public class UniqueConstraint : Constraint
public __gc class UniqueConstraint : public Constraint
class UniqueConstraint extends Constraint

Thread Safety

This type is suitable for multithreaded read operations. You must synchronize any write operations.


The UniqueConstraint is enforced on a single column (or columns) to ensure that a primary key value is unique.

Constraints are not enforced unless the EnforceConstraints property is set to true.

When the a DataSet is merged with a second DataSet, constraints are not enforced until all merges are completed.


[Visual Basic] The following example adds a UniqueConstraint to a DataSet and sets the EnforceConstraints property to true.

[Visual Basic] 
Public Sub CreateTable()
  Dim myTable As DataTable = New DataTable
  myTable.Columns.Add("CustomerID", Type.GetType("System.String"))
  myTable.Columns.Add("CompanyName", Type.GetType("System.String"))

  Dim myUC As UniqueConstraint = New UniqueConstraint("CustConstraint", _
                                     New DataColumn() {myTable.Columns("CustomerID"), _
                                                       myTable.Columns("CompanyName")} )
End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Data

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Data (in System.Data.dll)

See Also

UniqueConstraint Members | System.Data Namespace | Add | Constraint | Constraints | ConstraintCollection | DataRelation | ForeignKeyConstraint

© 2015 Microsoft