Gets or sets a value indicating whether the values in each row of the column must be unique.
[Visual Basic] Public Property Unique As Boolean [C#] public bool Unique {get; set;} [C++] public: __property bool get_Unique(); public: __property void set_Unique(bool); [JScript] public function get Unique() : Boolean; public function set Unique(Boolean);
true if the value must be unique; otherwise, false. The default is false.
Exception Type | Condition |
---|---|
ArgumentException | The column is a calculated column. |
The OnPropertyChanged event occurs when the property change is successful.
You can also add a UniqueConstraint to the DataTable to which this column belongs to ensure the values are unique.
The following example creates a new DataColumn and sets its Unique property to true.
[Visual Basic]
Private Sub MakeUniqueColumn() Dim myColumn As DataColumn Dim myTable As New DataTable myColumn = New DataColumn myTable = New DataTable ' Set the Unique property of the DataColumn. myColumn.Unique = True ' Add the column to the table. myTable.Columns.Add myColumn ' Add the Table to a DataSet. DataSet1.Tables.Add(myTable) End Sub
DataColumn Class | DataColumn Members | System.Data Namespace | AllowNull | UniqueConstraint | Constraints