Solved

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

Posted on 2008-10-13
5
742 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

16 Experts available now in Live!

Get 1:1 Help Now