Robert, Miha's suggestion is a great way to do it, but let me add something.
If you bind it to the table you will have some problems if you try to add a
value to the control that doesn't belong to the table. A common one is
providing ALL value at the top and then each of the values beneath it where
ALL isn't in the datatable. In such a case, you can add ALL as a DataRow
and it will appear. Another issue is when you don't want every value in the
table. In that case, you can do either
foreach(DataRow dr in myTable.Rows){ comboBox.Items.Add(dr(Index);}
or for(int i = 0; i < myTable.Rows.Count-1; i++){
comboBox.Items.Add(myTable.Rows
.[Index]
}
In general, the approach Miha suggests is the cleanest and easisest to
implement, but you can have some curve balls that might require a different
method.
HTH,
Bill
Robert A. Boudra said:
I would like to create a distinct list of last names from a data table,
then populate a combo box with these values. What's the best way to
accomplish this in ADO.net?
Bob