问题
I have a combo box that I am binding from a sql server database. I am binding one column from the database into the combo box. The problem is that I get the same item showing up in there several times. I am querying from a stored procedure. Let me know if there is anything obvious that I am missing. Thanks
public void BindComboBox()
{
_dsinventory = new DataSet();
_dsinventory = dbAccess.ExecuteQuery(InventoryOutputQuery.ComboBox_Type());
cmbType.ItemSource = _dsinventory.Tables[0].DefaultView;
cmbType.DisplayMemberPath = _dsinventory.Tables[0].Columns[Type].ToString();
}
回答1:
try distinct keyword in you select query
Select distinct columnname form table
回答2:
DISTINCT should only be used when you are sure that the query is all fine.
Double check the query you are using, and then go for DISTINCT.
来源:https://stackoverflow.com/questions/6372739/combobox-displaying-duplicate-items