DataColumn.Unique 屬性

定義

取得或設定值,指出在資料行之每個資料列中的值是否必須是唯一的。

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

屬性值

如果值必須是唯一的,則為 true,否則為 false。 預設為 false

屬性

例外狀況

該資料行是計算的資料行。

範例

下列範例會建立新的 DataColumn、設定其屬性,並將它新增至數據表的數據行集合。

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,就會在此數據行上建立唯一條件約束,以確保值是唯一的。

適用於

另請參閱