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

adding a select distinct query to the tableadapter

Posted on 2009-05-07
5
612 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-
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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