Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

System::Object
  System.Data::Constraint
    System.Data::UniqueConstraint

public ref class UniqueConstraint : Constraint

NameDescription
System_CAPS_pubmethodUniqueConstraint(DataColumn^)

Initializes a new instance of the UniqueConstraint class with the specified DataColumn.

System_CAPS_pubmethodUniqueConstraint(DataColumn^, Boolean)

Initializes a new instance of the UniqueConstraint class with the DataColumn to constrain, and a value specifying whether the constraint is a primary key.

System_CAPS_pubmethodUniqueConstraint(array<DataColumn^>^)

Initializes a new instance of the UniqueConstraint class with the given array of DataColumn objects.

System_CAPS_pubmethodUniqueConstraint(array<DataColumn^>^, Boolean)

Initializes a new instance of the UniqueConstraint class with an array of DataColumn objects to constrain, and a value specifying whether the constraint is a primary key.

System_CAPS_pubmethodUniqueConstraint(String^, DataColumn^)

Initializes a new instance of the UniqueConstraint class with the specified name and DataColumn.

System_CAPS_pubmethodUniqueConstraint(String^, DataColumn^, Boolean)

Initializes a new instance of the UniqueConstraint class with the specified name, the DataColumn to constrain, and a value specifying whether the constraint is a primary key.

System_CAPS_pubmethodUniqueConstraint(String^, array<DataColumn^>^)

Initializes a new instance of the UniqueConstraint class with the specified name and array of DataColumn objects.

System_CAPS_pubmethodUniqueConstraint(String^, array<DataColumn^>^, Boolean)

Initializes a new instance of the UniqueConstraint class with the specified name, an array of DataColumn objects to constrain, and a value specifying whether the constraint is a primary key.

System_CAPS_pubmethodUniqueConstraint(String^, array<String^>^, Boolean)

Initializes a new instance of the UniqueConstraint class with the specified name, an array of DataColumn objects to constrain, and a value specifying whether the constraint is a primary key.

NameDescription
System_CAPS_protproperty_DataSet

This API supports the product infrastructure and is not intended to be used directly from your code. Gets the DataSet to which this constraint belongs.(Inherited from Constraint.)

System_CAPS_pubpropertyColumns

Gets the array of columns that this constraint affects.

System_CAPS_pubpropertyConstraintName

The name of a constraint in the ConstraintCollection.(Inherited from Constraint.)

System_CAPS_pubpropertyExtendedProperties

Gets the collection of user-defined constraint properties.(Inherited from Constraint.)

System_CAPS_pubpropertyIsPrimaryKey

Gets a value indicating whether or not the constraint is on a primary key.

System_CAPS_pubpropertyTable

Gets the table to which this constraint belongs.(Overrides Constraint::Table.)

NameDescription
System_CAPS_protmethodCheckStateForProperty()

This API supports the product infrastructure and is not intended to be used directly from your code. Gets the DataSet to which this constraint belongs.(Inherited from Constraint.)

System_CAPS_pubmethodEquals(Object^)

Compares this constraint to a second to determine if both are identical.(Overrides Object::Equals(Object^).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Gets the hash code of this instance of the UniqueConstraint object.(Overrides Object::GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodSetDataSet(DataSet^)

Sets the constraint's DataSet.(Inherited from Constraint.)

System_CAPS_pubmethodToString()

Gets the ConstraintName, if there is one, as a string.(Inherited from 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"), _
      dataTable.Columns("CompanyName")})

    dataTable.Constraints.Add(uniqueConstraint)
End Sub

.NET Framework
Available since 1.1

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

Return to top
Show:
© 2017 Microsoft