Click here to Skip to main content
15,112,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a TableAdapter which references an Object Data Source and it's code is in a BLL code.

When it runs, i get:

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

I looked at all of the data and there are no duplicates on the primary key field, no null or blank fields and all fields have AllowDBNull=False.

I deleted the datatable and recreated it by dropping the table from the database on to the dataset.

I tried setting EnforceConstraints=False

I read dozens of forum posts here about this subject and cannot figure out why this is happening. All i want to do is populate the dropdownlist with a set of unique warhouse numbers.

Any help would be gratefully appreciated.
Updated 13-Nov-14 1:29am

1 solution

This problem is usually caused by one of the following

*null values being returned for columns not set to AllowDBNull
*duplicate rows being returned with the same primary key.
*a mismatch in column definition (e.g. size of char fields) between the database and the dataset
Try running your query natively and look at the results, if the resultset is not too large. If you've eliminated null values, then my guess is that the primary key columns is being duplicated.

Or, to see the exact error, you can manually add a Try/Catch block to the generated code like so and then breaking when the exception is raised:

Also you can use SQL Server Profiler so that you can find where the error actually occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900