ComboBox显示许多数据

时间:2015-02-10 00:28:15

标签: c# combobox

我这里有问题。我希望我的组合ComboBox列出唯一数据,但它似乎有多个示例 enter image description here

FEB 1,我有一个采购订单编号,并在CounterChecking

重复多次

这是我的代码;

try
        {

            SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["POSdb"].ConnectionString);

            sc.Open();


            string strQry = "SELECT po_no"+
                " FROM CounterChecking";
            SqlCommand scmd = new SqlCommand(strQry, sc);
            SqlDataReader dr = scmd.ExecuteReader();

            DataTable dt = new DataTable();
            dt.Columns.Add("po_no", typeof(string));
            dt.Load(dr);

            cb_po_search.ValueMember = "po_no";
            cb_po_search.DisplayMember = "po_no";
            cb_po_search.DataSource = dt;

            sc.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

1 个答案:

答案 0 :(得分:1)

如果您的CounterChecking表格包含多个PO编号,那么您的sqlQry应根据po_no列进行分组,以获得唯一列表。

查询应该是;

sqlQry = "SELECT po_no"+ " FROM CounterChecking GROUP BY po_no";