“Failed to enable constraints. One or more rows contain values violating…”
November 2, 2006
Using DataSets with TableAdapters I was trying to retrieve the different years listed in a database table since I wanted the unique years to show up on a drop-down list. My SQL-query looked like this:
SELECT DISTINCT DATEPART(yyyy, EntryDate) AS Year
FROM nPressClips
ORDER BY Year DESC
What happened was that the dataset couldn’t fill due to this error:
“Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.”
For some reason unknown to me, the query above also returned a null value PressClipID-column that I didn’t want. A quick solution was to simply return a constant column value to avoid it being null. This is my solution, quick and very dirty:
SELECT DISTINCT DATEPART(yyyy, EntryDate) AS Year, 1 AS PressClipID
FROM nPressClips
ORDER BY Year DESC
If anyone can come up with a better solution than this, do not hesitate to contact me. Until then, this works just fine.
July 26, 2007 at 11:41
you could set the dataset constraints to false as below.
variable = New
variable.EnforceConstraints = False
This way all the fields will be loaded into the dataset.
hope this helps.
November 30, 2007 at 08:02
Really superb..
Now I run my application without any compilation error
so Thank You…..
June 25, 2008 at 04:51
Thanks, the clue to make EnforceConstraints=false helped me resolve out my problem too. Thanks for making it avialable.
June 3, 2010 at 11:54
Tks
September 5, 2011 at 19:42
Thank so much Mike.Ke. Your help were very important to me..