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

Important note: Hi folks. This post was written in 2004. Yes, people have been getting this for over 6 years . It’s 2011 now, and here you are, still stuck working on this crap. I highly suggest you read this, as an alternative rout to solve your problems.
Thanks, Roy in 2011.
================================
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 to this post so I pasted them all in at the bottom- 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…
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值