【问题标题】:how to join tow combobox data如何连接两个组合框数据
【发布时间】:2017-09-14 00:20:57
【问题描述】:

我有两个组合框,第一个组合框代码是从两个不同的表加载数据

>  OleDbCommand cmd = new OleDbCommand("select empno,ename from emp", con);
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                combobox1.Items.Add(dr[1].ToString());

            }

结果:

KING

BLAKE

CLARK

第二个组合框代码是

> OleDbCommand cmd1 = new OleDbCommand("select UnitId,UnitName from
> TableUnit", con);
>             OleDbDataReader dr1 = cmd1.ExecuteReader();
>             while (dr1.Read())
>             {
>                 combobox2.Items.Add(dr1[1].ToString());
>             }

结果:

ACCOUNTING

RESEARCH

SALES

OPERATIONS

我怎样才能让加载数据将两个结果(combobox1+combobox2)加入到 combobox3 中,例如

KING  ACCOUNTING

BLAKE RESEARCH

【问题讨论】:

    标签: c# sql oracle combobox


    【解决方案1】:

    您可以通过以下方式合并第三个组合框中的两个组合框内容:

    for (int i = 0; i < (combobox1.Items.Count < combobox2.Items.Count ? combobox1.Items.Count : combobox2.Items.Count); i++)
    {
           combobox3.Items.Add($"{combobox1.Items[i]} {combobox2.Items[i]}");
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 2016-05-05
      • 2014-03-23
      • 2012-10-02
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多