如何加入两个组合框数据

时间:2017-09-14 00:20:57

标签: c# sql oracle combobox

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

>  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

1 个答案:

答案 0 :(得分:0)

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

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]}");
}