Friday, March 23, 2012

Failed to enable constraints. One or more rows contain values violating non-null, unique, or for

Hello all, I just want to make a quick post on the “Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.”

I am working on a small system at the moment and I have a CODES table with columns CODE and DESC. When I first set up the database I set CODE to varchar(MAX) and same with DESC, Then when I put all the codes and descriptions in and tried to run fill I got the error.

Now weather this will help anyone I don’t know, I found out that it was the Colum DESC in the DataSet that was causing the problem, if you enter your dataset designer and select one of your columns, Right click, properties, there is a field called MAXLENGTH, When I checked it was set to 50 even though I had set varchar(MAX), so I knew that some of my descriptions where bigger than 50 so I upped it to 100 and everything was working fine. I don’t know if this will be applicable to everyone or just me for being stupid but hey, it worked ;)

Moved to SQL server - seems off topic for the VS debugger.|||

I got the same error message because my dataset had columns with minoccur property as null but there were no records in the database. Some of these columns were nullable in the database but not marked as 0 in dataset minoccur property.

Solution - For every column thats marked as nullable in database, I set the minoccur property to 0. This makes dataser expect null values

|||hello I'm new using c# I would like to know how to put the minoccur property to 0. Im having the same error
thanks

No comments:

Post a Comment