Wednesday, August 19, 2009

System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

I occasionally have a problem when trying to use TableAdapter

System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

In my case this happened because we did not include any of the primary keys in table joins.

My Solution:

You may want to try this using your DataSet Designer.
  1. Open the dataset designer
  2. Go to the TableAdapter in question
  3. Find where the primary key is set
  4. Right click over and select Primary Key menu
  5. Change the key to something else that make more sense

Post a Comment