DataColumn.Unique Egenskap

Definition

Hämtar eller anger ett värde som anger om värdena i varje rad i kolumnen måste vara unika.

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

Egenskapsvärde

trueom värdet måste vara unikt. annars . false Standardvärdet är false.

Attribut

Undantag

Kolumnen är en beräknad kolumn.

Exempel

I följande exempel skapas nya DataColumn, anger dess egenskaper och lägger till dem i en tabells kolumnsamling.

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

Kommentarer

Så snart den här egenskapen ändras från false till true skapas en unik begränsning i den här kolumnen för att se till att värdena är unika.

Gäller för

Se även