Dela via


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

  1. Open the dataset in the Dataset Designer.

  2. Right-click the column you want to add the constraint to.

  3. Point to Add, and then select Key.

To display this dialog box in an untyped dataset

  1. Select the untyped dataset in the form or component.

  2. In the Properties window, click the button in the Tables property to display the Tables Collection Editor.

  3. In the Members list, select the table to define a constraint for.

  4. Select the Constraints property and click the button next to (Collection).

  5. 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

Concepts

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Connecting to Data in Visual Studio