Link to home
Start Free TrialLog in
Avatar of RobertNZana
RobertNZanaFlag for United States of America

asked on

Gridview has "Failed to enable constraints" error...

I have a gridview that is databound to an objectdatasource.  The ODS utilizes a XSD Dataset that was created.

I keep getting this error when viewing the page:  Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

The query (MySQL) works fine thru the query tool.

I MANUALLY checked the data and it is fine as well.

Here's the actual query...
SELECT DISTINCT companytypes.CompanyType, users.Company, users.CompanyTypeId, users.ContactAddress1, users.ContactAddress2, users.ContactCity,users.ContactState, users.ContactZip, users.ContactPhone, users.ContactFax, users.CompanyDescription
FROM users INNER JOIN companytypes ON users.CompanyTypeId = companytypes.CompanyTypeId
ORDER BY companytypes.CompanyType, users.Company

When I create a MySqlDataSource (using DevArt's MyDirect.NET) and bind the gridview directly to it, putting the exact same SQL, it works fine.

Any ideas?
Avatar of strickdd
strickdd
Flag of United States of America image

You should check the setup of the dataset. Any field that is a string, you should set the default to be "(Empty)" instead of "(Throw Exception)". Also, I usually remove the primary key from the dataset.
Avatar of RobertNZana

ASKER

The data comes from 2 tables, Users and CompanyTypes (linked by the fk CompanyTypeId).  

In a new XSD I dropped the Users table on the designer.  I then created a new query in the adapter.  I unchecked a few of the fields, including the pk.  When I'm done I get the message that "The new command text returns data with schema different from the schema of the main query.  Check your query's command text if this is not desired."

When I go to "Preview Data" on the query the results shows all the fields, even the ones I unchecked!  But, these columns are empty, except for the pk, with is -1, -2, -3, etc...

Could this be the problem?  Why would these fields show up in the preview data????
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are these fields why I'm getting that "Failed to enable constraints" error?

The SQL query works in the MySQL Query Tool as well as if I put the query straight in a MySqlDataSource.
figured it out myself