Click here to Skip to main content
14,333,875 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
v4
Rate this:
Please Sign up or sign in to vote.

Solution 1

Go through your resultset and add each item to a new collection, but only if they are not already in the collection.

Nick
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100