Represents a restriction on a set of columns in which all values must be unique.
public ref class UniqueConstraint : System::Data::Constraint
public class UniqueConstraint : System.Data.Constraint
[System.Serializable]
public class UniqueConstraint : System.Data.Constraint
type UniqueConstraint = class
inherit Constraint
[<System.Serializable>]
type UniqueConstraint = class
inherit Constraint
Public Class UniqueConstraint
Inherits Constraint
The following example adds a UniqueConstraint to a DataSet and sets the EnforceConstraints property to true
.
Public Sub CreateDataTable()
Dim dataTable As 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
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.
Constructors UniqueConstraint(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.
UniqueConstraint(DataColumn)Initializes a new instance of the UniqueConstraint class with the specified DataColumn.
UniqueConstraint(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.
UniqueConstraint(DataColumn[])Initializes a new instance of the UniqueConstraint class with the given array of DataColumn objects.
UniqueConstraint(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.
UniqueConstraint(String, DataColumn)Initializes a new instance of the UniqueConstraint class with the specified name and DataColumn.
UniqueConstraint(String, 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.
UniqueConstraint(String, DataColumn[])Initializes a new instance of the UniqueConstraint class with the specified name and array of DataColumn objects.
UniqueConstraint(String, 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.
Properties Methods Thread SafetyThis type is suitable for multithreaded read operations. You must synchronize any write operations.
See alsoCollaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4