Failed to enable constraints.

T

tma

I've got a SELECT statement that, when run in the Enterprise Manager, works
great. However, when I use that same statement in a
SelectCommand.CommandText string, I get the following error. Can anyone tell
me what I need to look for?
Failed to enable constraints. One or more rows contain values violating
non-null, unique, or foreign-key constraints.
 
W

W.G. Ryan eMVP

Look at your dataset - you probably have something there that doesn't allow
nulls and you have a null value. It could be a key - do you have any
datarelations and/ or keys on the table? Set the EnforceConstraints to false
(just to try to debug this) but that's just a band aid - look for the cause
which is probably a null - or a key violation.
http://weblogs.asp.net/rosherove/archive/2004/10/03/237260.aspx
 
M

Miha Markic [MVP C#]

Or just do a foreach on every row (after exception occured) and check each
row's RowError property.
If you have several tables, you might also check DataTable.HasErrors
property to limit the search.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top