Combobox displaying duplicate items

丶灬走出姿态 提交于 2020-01-04 05:18:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!