Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …

837 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