DataColumn.Unique Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
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.