DataSet hell - "Failed to enable constraints. One or more rows contain values...."

A friend asks:

When I fill my dataset I get this:
"Failed to enable constraints. One or more rows  contain values violating non-null, unique, or foreign-key  constraints."
As you can see, "one or more" is not very informative. How do I identify the criminal ?
Since the only solution I know is to go through each table and compare it's constraints,
Is there a more efficient way to solve this ?

I'll admit this is one of the more annoying problems I've encountered when working with the Dataset object. 
And no - I don't know an easy way to find out who the culprit is. Do you? Please share in the comments.
Update (plenty of good comments below this post - make sure to read through them..):
In the comments to this post, Sanjay gives a good answer to this problem:
"The solution lies in the GetErrors method of the DataTable class:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataDataTableClassGetErrorsTopic.asp

Essentially, when I see the message above, I check the HasErrors property for each DataTable in the data set and then invoke the GetErrors method on the tables reporting errors. The GetErrors returns a collection of DataRows and you can invoke the .RowError property on the each of the error-stricken rows to find out just exactly what the problem is . "          
 ."..I forgot to add the part about turning off the .EnableConstraints before the Fill. I normally enable the constraints again, only after the original Fill is complete. Then, you can catch the exception above and launch a error detection function which does what I described above. "
Thanks, Sanjay! Lots of other good comments and differetn solutions as well...
Published Sunday, October 03, 2004 10:45 PM by RoyOsherove
Filed under:

Comments

No Comments