DataSet hell - "Failed to enable constraints. One or more rows contain values...."
2011-08-24 16:55
477 查看
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 ?
“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…
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…
相关文章推荐
- 源码调试Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- DataTable - Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
- dell装机bios问题 os install mode enable failed to detect one or more drives during post
- Geoserver fails One or more listeners failed to start
- arcgis的One or more layers failed to draw: 问题
- 【报错】项目启动,仅仅报错 One or more listeners failed to start. Full details will be found in the appropriate container log file
- Cannot change version of project facet Dynamic Web Module to 2.5. 和 One or more constraints have not
- Failed to instantiate one or more classes
- android的imageView出现failed to instantiate one or more classes
- Tomcat 8报错 SEVERE: One or more listener failed to start,如何找到更详细的错误信息
- one or more listeners failed to start
- One or more listeners failed to start. Full details will be found in the appropriate container log
- One or more Filters failed to start. Full details will be found in the appropriate container log fil
- 关于One or more listeners failed to start的问题排查
- bug笔记 - Spring --- Tomcat 报错: SEVERE: One or more listeners failed to start.