DataColumn.Unique Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy wartości w każdym wierszu kolumny muszą być unikatowe.

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

Wartość właściwości

true jeśli wartość musi być unikatowa; w przeciwnym razie , false. Wartość domyślna to false.

Atrybuty

Wyjątki

Kolumna jest kolumną obliczeniową.

Przykłady

W poniższym przykładzie tworzony jest nowy DataColumnobiekt , ustawia jego właściwości i dodaje go do kolekcji kolumn tabeli.

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

Uwagi

Gdy tylko ta właściwość zostanie zmieniona z false na true, w tej kolumnie zostanie utworzone unikatowe ograniczenie, aby upewnić się, że wartości są unikatowe.

Dotyczy

Zobacz też