• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

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.
0
-Dman100-
Asked:
-Dman100-
  • 3
  • 2
1 Solution
 
mohan_sekarCommented:
If they don't matter, then disable the constraints when you call Fill
0
 
-Dman100-Author Commented:
Hi Mohan,

Thanks for the reply.  How do you disable the contraints programmatically?  I haven't done that before.  Can you advise?
0
 
mohan_sekarCommented:
Just set <datasetname>.EnforceConstraints = False
0
 
-Dman100-Author 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-Author 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now