Solved

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

Posted on 2008-10-13
5
741 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:RobertNZana
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 22703948
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.
0
 
LVL 9

Author Comment

by:RobertNZana
ID: 22704375
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????
0
 
LVL 28

Accepted Solution

by:
strickdd earned 125 total points
ID: 22706170
if the fields are in the Table Adapter, they will show up in the Preview Data option. Since you aren't selecting those fields, they will be null or negative integers.
0
 
LVL 9

Author Comment

by:RobertNZana
ID: 22706275
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.
0
 
LVL 9

Author Closing Comment

by:RobertNZana
ID: 31407077
figured it out myself
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now