Unique Constraint Dialog Box
Allows you to place a unique constraint on one or more columns in a data table, guaranteeing that no values in a column or combination of columns are duplicated. For example, primary key columns always have unique constraints. At run time, a unique constraint raises an error if there is an attempt to put a duplicate value into the constrained columns.
User Interface Element List
Name
The literal name of the constraint object. The name is used when referencing the constraint in code and as an identifier when you are editing the constraint in the Properties window.Columns
Determines the column or columns involved in the constraint. Typically you create a unique constraint for a single column. However, you can also create a constraint that checks for uniqueness in a combination of columns — individual column values might be repeated, but the combination of values from the constrained columns is unique.Primary key
Designates this constraint as the table's primary key. This setting causes other changes to be made in the dataset definition, including:The table's PrimaryKey property (an array) is set to reflect the columns you specified for the constraint.
The Unique property of each column in the constraint is set to true.
The AllowDBNull property of each column in the constraint is set to false.
Opening the Unique Constraint Dialog Box
To display this dialog box in a typed dataset
Open the dataset in the Dataset Designer.
Right-click the column you want to add the constraint to.
Point to Add, and then select Key.
To display this dialog box in an untyped dataset
Select the untyped dataset in the form or component.
In the Properties window, click the button in the Tables property to display the Tables Collection Editor.
In the Members list, select the table to define a constraint for.
Select the Constraints property and click the button next to (Collection).
In the Constraints Collection Editor, click Add and select UniqueConstraint.
See Also
Tasks
How to: Set a Data Column as the Primary Key
How to: Restrict a Data Column to Contain Unique Values
Other Resources
Connecting to Data in Visual Studio
Preparing Your Application to Receive Data
Fetching Data into Your Application
Displaying Data on Forms in Windows Applications