Επεξεργασία

Κοινή χρήση μέσω


DataColumn.Unique Property

Definition

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); };
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

Property Value

true if the value must be unique; otherwise, false. The default is false.

Attributes

Exceptions

The column is a calculated column.

Examples

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

Remarks

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.

Applies to

See also