Distinct values in Dropdown LIST

  • Thread starter Thread starter Seelan
  • Start date Start date
S

Seelan

Hey Guys,
I have read a table from SQL Server to a Dataset called ds. Now I want
to list the items of one column to a DropDown List...I can do this perfectly
but i want ht e list to contain DISTINCT items without having to call the
SQLCommand again!
Please help thanks!
Seelan-
 
You can use FindStringExact to find the text of your item and not add them
if it's already there.

Or if you have a ton of items and don't want to have the perf hit, you could
create a hash table; check against the hash table before adding to the list
and populate it as you fill the list.

HTH

-vJ
 
There're a few choices in the System.Collections and
System.Collections.Specialized namespace. If you want only to check if the
object has been added or not, you could use GetHashCode() method in the
string that you're adding and throw it into a sorted array. That way you
will be comparing integers instead of strings (which is way more faster).

Or if you want to get back to the original object, you can use
StringDictionary and use ContainsKey() method to check if an item is already
in the dictionary.

For case insensitive matches, you can try CaseInsensitiveHashCodeProvider
class.

-vJ
 
Back
Top