0

I have a combobox I need to display some data in from a Database, but there are duplicates and I don't know how to select the distinct ones.

Any help?

4
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by pseudorandom21
Featured Replies
  • Have you tried doing SELECT DISTINCT ? i've had this proplem in the past and i think i used SELECT DISTINCT. Read More

  • Another option depending on how you get the data is to use Linq and call distinct on the object that holds the data. If it's something like a List<string> named lst_strData, you can call lst_strData.Distinct(); or pseudo-code [CODE] // GetDataFromSource would return a List<string> or array, etc. List<string> lst_strData = … Read More

1

Have you tried doing SELECT DISTINCT ? i've had this proplem in the past and i think i used SELECT DISTINCT.

0

Yep, SELECT DISTINCT will provide you with a list of the unique values in the table. Records that are in the table twice or more will only be in the resulting dataset once.

1

Another option depending on how you get the data is to use Linq and call distinct on the object that holds the data. If it's something like a List<string> named lst_strData, you can call lst_strData.Distinct();

or pseudo-code

// GetDataFromSource would return a List<string> or array, etc.
List<string> lst_strData = GetDataFromSource().Distinct().ToList();
0

Well I found the solution but it isn't using "SELECT DISTINCT" which I had already tried...

For some reason:

DataView view = autoDealershipDataSet.tblCars.DefaultView;
            DataTable distinctTable = view.ToTable("DistinctMakeTable", true, "Make");

            this.tblCarsBindingSource.DataSource = distinctTable;
            this.tblCarsBindingSource.ResetBindings(true);

You can't use the Filter property of a binding source to select distinct items, there is a crappy work-around.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.