UniqueConstraint UniqueConstraint UniqueConstraint UniqueConstraint Class

定義

表示所有值都必須是唯一的資料行集限制。Represents a restriction on a set of columns in which all values must be unique.

public ref class UniqueConstraint : System::Data::Constraint
[System.Serializable]
public class UniqueConstraint : System.Data.Constraint
type UniqueConstraint = class
    inherit Constraint
Public Class UniqueConstraint
Inherits Constraint
繼承
UniqueConstraintUniqueConstraintUniqueConstraintUniqueConstraint
屬性

範例

下列範例會將加入UniqueConstraint DataSet至, 並將EnforceConstraints屬性設定為trueThe 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

備註

UniqueConstraint會在單一資料行 (或資料行) 上強制執行, 以確保主鍵值是唯一的。The UniqueConstraint is enforced on a single column (or columns) to ensure that a primary key value is unique.

除非EnforceConstraints屬性設定為true, 否則不會強制執行條件約束。Constraints are not enforced unless the EnforceConstraints property is set to true.

當 a DataSet與第二個DataSet合併時, 在所有合併完成之前, 不會強制執行條件約束。When the a DataSet is merged with a second DataSet, constraints are not enforced until all merges are completed.

建構函式

UniqueConstraint(DataColumn) UniqueConstraint(DataColumn) UniqueConstraint(DataColumn) UniqueConstraint(DataColumn)

使用指定的 UniqueConstraint 初始化 DataColumn 類別的新執行個體。Initializes a new instance of the UniqueConstraint class with the specified DataColumn.

UniqueConstraint(DataColumn, Boolean) UniqueConstraint(DataColumn, Boolean) UniqueConstraint(DataColumn, Boolean) UniqueConstraint(DataColumn, Boolean)

使用要限制的 UniqueConstraint 和指定條件約束是否為主索引鍵的值,來初始化 DataColumn 類別的新執行個體。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[]) UniqueConstraint(DataColumn[]) UniqueConstraint(DataColumn[]) UniqueConstraint(DataColumn[])

使用 UniqueConstraint 物件的指定陣列,初始化 DataColumn 類別的新執行個體。Initializes a new instance of the UniqueConstraint class with the given array of DataColumn objects.

UniqueConstraint(DataColumn[], Boolean) UniqueConstraint(DataColumn[], Boolean) UniqueConstraint(DataColumn[], Boolean) UniqueConstraint(DataColumn[], Boolean)

使用要限制的 UniqueConstraint 物件陣列和指定條件約束是否為主索引鍵的值,來初始化 DataColumn 類別的新執行個體。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(String, DataColumn) UniqueConstraint(String, DataColumn) UniqueConstraint(String, DataColumn) UniqueConstraint(String, DataColumn)

使用指定名稱和 UniqueConstraint 來初始化 DataColumn 類別的新執行個體。Initializes a new instance of the UniqueConstraint class with the specified name and DataColumn.

UniqueConstraint(String, DataColumn, Boolean) UniqueConstraint(String, DataColumn, Boolean) UniqueConstraint(String, DataColumn, Boolean) UniqueConstraint(String, DataColumn, Boolean)

使用指定名稱、要限制的 UniqueConstraint 和指定條件約束是否為主索引鍵的值,來初始化 DataColumn 類別的新執行個體。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[]) UniqueConstraint(String, DataColumn[]) UniqueConstraint(String, DataColumn[]) UniqueConstraint(String, DataColumn[])

使用指定名稱和 UniqueConstraint 物件的陣列,來初始化 DataColumn 類別的新執行個體。Initializes a new instance of the UniqueConstraint class with the specified name and array of DataColumn objects.

UniqueConstraint(String, DataColumn[], Boolean) UniqueConstraint(String, DataColumn[], Boolean) UniqueConstraint(String, DataColumn[], Boolean) UniqueConstraint(String, DataColumn[], Boolean)

使用指定名稱、要限制的 UniqueConstraint 物件陣列和指定條件約束是否為主索引鍵的值,來初始化 DataColumn 類別的新執行個體。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, String[], Boolean) UniqueConstraint(String, String[], Boolean) UniqueConstraint(String, String[], Boolean) UniqueConstraint(String, String[], Boolean)

使用指定名稱、要限制的 UniqueConstraint 物件陣列和指定條件約束是否為主索引鍵的值,來初始化 DataColumn 類別的新執行個體。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.

屬性

Columns Columns Columns Columns

取得這個條件約束影響的資料行陣列。Gets the array of columns that this constraint affects.

ConstraintName ConstraintName ConstraintName ConstraintName

ConstraintCollection 中的條件約束名稱。The name of a constraint in the ConstraintCollection.

(Inherited from Constraint)
ExtendedProperties ExtendedProperties ExtendedProperties ExtendedProperties

取得使用者定義條件約束屬性的集合。Gets the collection of user-defined constraint properties.

(Inherited from Constraint)
IsPrimaryKey IsPrimaryKey IsPrimaryKey IsPrimaryKey

取得數值,指示條件約束是否在主索引鍵上。Gets a value indicating whether or not the constraint is on a primary key.

Table Table Table Table

取得這個條件約束所屬的資料表。Gets the table to which this constraint belongs.

_DataSet _DataSet _DataSet _DataSet

取得這個條件約束所屬的 DataSetGets the DataSet to which this constraint belongs.

(Inherited from Constraint)

方法

CheckStateForProperty() CheckStateForProperty() CheckStateForProperty() CheckStateForProperty()

取得這個條件約束所屬的 DataSetGets the DataSet to which this constraint belongs.

(Inherited from Constraint)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

將這個條件約束和第二個條件約束相比較,以判斷兩者是否相同。Compares this constraint to a second to determine if both are identical.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

取得 UniqueConstraint 物件的這個執行個體之雜湊程式碼。Gets the hash code of this instance of the UniqueConstraint object.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
SetDataSet(DataSet) SetDataSet(DataSet) SetDataSet(DataSet) SetDataSet(DataSet)

設定條件約束的 DataSetSets the constraint's DataSet.

(Inherited from Constraint)
ToString() ToString() ToString() ToString()

取得 ConstraintName (如果有) 做為字串。Gets the ConstraintName, if there is one, as a string.

(Inherited from Constraint)

適用於

執行緒安全性

此類型適用于多執行緒讀取作業。This type is suitable for multithreaded read operations. 您必須同步處理任何寫入作業。You must synchronize any write operations.

另請參閱