constraintName is the name you want to assign to your constraint. isPrimaryKey indicates whether the constraint is a primary key constraint or just a regular unique constraint. | constraintName is the name you want to assign to your constraint. isPrimaryKey indicates whether the constraint is a primary key constraint or just a regular unique constraint. The following example uses the Add method to add a primary key constraint to the Products DataTable Orders . Primary key constraint Orders .Columns OrderlD true This example does the same thing as the previous example that added the primary key constraint using the PrimaryKey property. Notice the last parameter to the Add method is set to true which indicates the constraint is for a primary key. Just as an aside if you have a column that isn t a primary key but is unique you can add a UniqueConstraint object to the ConstraintsCollection. For example UniqueConstraint myUC new UniqueConstraint myColumn myU C Adding a Primary Key to the OrderDetails DataTable Let s consider an example of setting the PrimaryKey property for the Order Details DataTable. The primary for the Order Details table is made up of the OrderlD and ProductID columns and the following example sets the PrimaryKey property of the Order Details DataTable to these two columns Order Details .PrimaryKey new DataColumn Order Details .Columns OrderID Order Details .Columns ProductID The following example uses the Add method to do the same thing Order Details . Primary key constraint new DataColumn Order Details .Columns OrderID Order Details .Columns ProductID true One thing to keep in mind when adding constraints to a DataTable is that it knows only about the rows you store in it it doesn t know about any other rows stored in the actual database table. To see why this is an issue consider the following scenario that involves primary keys 1. You add a primary key constraint to a DataTable. 2. You retrieve a subset of the