Solved

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

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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