UniqueConstraint Class

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

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

Public Class UniqueConstraint
	Inherits Constraint
Dim instance As UniqueConstraint

public class UniqueConstraint extends Constraint
public class UniqueConstraint extends Constraint

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.

The following example adds a UniqueConstraint to a DataSet and sets the EnforceConstraints property to true.

Public Sub CreateDataTable()
    Dim dataTable As DataTable = New DataTable
    dataTable.Columns.Add("CustomerID", Type.GetType("System.String"))
    dataTable.Columns.Add("CompanyName", Type.GetType("System.String"))

    Dim uniqueConstraint As UniqueConstraint = _
      New UniqueConstraint("CustConstraint", _
      New DataColumn() {dataTable.Columns("CustomerID"), _

End Sub


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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0