Solved

adding a select distinct query to the tableadapter

Posted on 2009-05-07
5
626 Views
Last Modified: 2012-05-06
I have created a stronly typed dataset that fills a datatable from the Northwind customers table...i.e. Fill,GetCustomers()

Now, I want to add a new cuery where I select the distinct countries from the same table
SELECT DISTINCT Coutry FROM customers

I can add this query to the existing tableadapter, but it gives me a warning that the schema is not the same.  Then when I try to populate a dropdown with the FillCountries query, I get a constraint violation.
Error:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Thanks for any help.
0
Comment
Question by:-Dman100-
[X]
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
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24329239
If they don't matter, then disable the constraints when you call Fill
0
 

Author Comment

by:-Dman100-
ID: 24329256
Hi Mohan,

Thanks for the reply.  How do you disable the contraints programmatically?  I haven't done that before.  Can you advise?
0
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 500 total points
ID: 24329331
Just set <datasetname>.EnforceConstraints = False
0
 

Author Comment

by:-Dman100-
ID: 24330798
Hi mohan,

I set the EnforceConstraints property to false on my dataset, but when I run the page, I'm still getting the following error:

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.


Line 1139:                dataTable.Clear();
Line 1140:            }
Line 1141:            int returnValue = this.Adapter.Fill(dataTable);
Line 1142:            return returnValue;
Line 1143:        }

Open in new window

0
 

Author Comment

by:-Dman100-
ID: 24330926
It looks like since the second query using distinct does not contain all the columns in the default query returning all the columns that it blows up and causes the error.

Is there a way around this or do I have to create a second tableadapter just to handle the distinct clause?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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