DataColumn.Unique DataColumn.Unique DataColumn.Unique DataColumn.Unique Property

定義

取得或設定值,指出在資料行之每個資料列中的值是否必須是唯一的。Gets or sets a value that indicates whether the values in each row of the column must be unique.

public:
 property bool Unique { bool get(); void set(bool value); };
[System.Data.DataSysDescription("DataColumnUniqueDescr")]
public bool Unique { get; set; }
member this.Unique : bool with get, set
Public Property Unique As Boolean

屬性值

如果值必須是唯一的,則為 true,否則為 falsetrue if the value must be unique; otherwise, false. 預設為 falseThe default is false.

例外狀況

該資料行是計算的資料行。The column is a calculated column.

範例

下列範例會建立新DataColumn的、設定其屬性,並將其加入至資料表的資料行集合。The following example creates new DataColumn, sets its properties, and adds it to a table's columns collection.

private void AddColumn(DataTable table)
{
    // Add a DataColumn to the collection and set its properties.
    // The constructor sets the ColumnName of the column.
    DataColumn column = new DataColumn("Total");
    column.DataType = System.Type.GetType("System.Decimal");
    column.ReadOnly = true;
    column.Expression = "UnitPrice * Quantity";
    column.Unique = false;
}
Private Sub AddColumn(table As DataTable)
    ' Add a DataColumn to the collection and set its properties.
    ' The constructor sets the ColumnName of the column.
    Dim column As New DataColumn("Total")
    column.DataType = System.Type.GetType("System.Decimal")
    column.ReadOnly = True
    column.Expression = "UnitPrice * Quantity"
    column.Unique = False
End Sub

備註

一旦此屬性從 false 變更為 true,就會在此資料行上建立 unique 條件約束,以確保值是唯一的。As soon as this property is changed from false to true, a unique constraint will be created on this column to make sure that values are unique.

適用於

另請參閱