Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three dropdown lists which I'm fetching the values for from a database (SQL Server). I need only unique values to show in the dropdown list.

How can I do this?

Thanks in advance
Posted
Updated 23-Mar-10 8:34am
v2

While fetching the values from database, you must be using SQL queries.

Use DISTINCT in the SQL Query and retrieve only unique values!

==============
From JSOP: DISTINCT may not be waht he needs. He could need to sum values (or some other aggregate functionality), at which point he'd provbably want to use GROUP BY.

Assuming he got his data already, he'd probably want to use LINQ to pull distinct records out of the dataset according to the requirements of his combo boxes. Unfortunately, his question doesn't present even info for us to provide him with the answer he needs.

UPDATE on JSOP: I agree with you, what you say is correct. Though based on what he is trying to achieve, it does not look like he must be grouping by or using any aggregate functionality - just getting dropdownlist data (some id and a respective display value in a general case!)... SQL query should be fine and enough.
 
Share this answer
 
v4
Go through your resultset and add each item to a new collection, but only if they are not already in the collection.

Nick
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900