adding a select distinct query to the tableadapter

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.
-Dman100-Software ConsultantAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mohan_sekarConnect With a Mentor Commented:
Just set <datasetname>.EnforceConstraints = False
0
 
mohan_sekarCommented:
If they don't matter, then disable the constraints when you call Fill
0
 
-Dman100-Software ConsultantAuthor Commented:
Hi Mohan,

Thanks for the reply.  How do you disable the contraints programmatically?  I haven't done that before.  Can you advise?
0
 
-Dman100-Software ConsultantAuthor Commented:
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
 
-Dman100-Software ConsultantAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.