Failed to enable constraints

I faced the same problem like others. When you use strongly typed datasets, while loading the data, I enable the constraints and while doing that,it throws me this error.

“Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints”

Ok I understand that there are one or more columns has null values which conflicts the constraints. But I have 20 different tables and each table has 25 different columns and of which 10 or more are “Not null” columns. See where I am going? Like Drew mentioned why don't this ConstraintException  gives me little more useful information such as which table and column name.

I needed to go through all the tables and check whether “haserrors” property was set to True and if so check all the “Not null” columns. sigh!  Don't know any other better ways..

2 Comments

  • maybe I am dense, but I am working through the beginners tutorials with.NET Visual Studio and got the same error message. The error pointed to my second oleDBDataAdapter. I have a parent table and a child table, both of which have nulls in several columns. I bound my controls to the dataset, but what now?



    What do you mean check 'has errors' property set to true and if so check all 'not null columns (in the tables)?

  • DY,



    Every table in the dataset has a property called "HasErrors" which will have true if there is any error. If you find any table with HasErrors true, then you can rest assured that you are NOT passing value for one of its required columns(you must have set not null in your tables) and hence solve the problem



    Hopt this helps

Comments have been disabled for this content.