Solved

adding a select distinct query to the tableadapter

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Not showing JavaScript in the list 5 54
imap mails 1 23
tutorial for ebay api 3 35
Please explain the parts of these 2 LINQ expressions 3 33
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.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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