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.