Solved

adding a select distinct query to the tableadapter

Posted on 2009-05-07
5
572 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
Comment Utility
If they don't matter, then disable the constraints when you call Fill
0
 

Author Comment

by:-Dman100-
Comment Utility
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
Comment Utility
Just set <datasetname>.EnforceConstraints = False
0
 

Author Comment

by:-Dman100-
Comment Utility
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-
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now