語言

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,該欄位就會建立唯一的限制,以確保值是唯一的。

適用於

另請參閱