DataColumn.Unique Propriedade

Definição

Recebe ou define um valor que indica se os valores em cada linha da coluna devem ser únicos.

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

Valor de Propriedade

true se o valor tiver de ser único; caso contrário, false. A predefinição é false.

Atributos

Exceções

A coluna é uma coluna calculada.

Exemplos

O exemplo seguinte cria novos DataColumn, define as suas propriedades e adiciona-o à coleção de colunas de uma tabela.

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

Observações

Assim que esta propriedade for alterada de falso para verdadeiro, será criada uma restrição única nesta coluna para garantir que os valores são únicos.

Aplica-se a

Ver também