0

我有以下查询,它从两个不同的表中获取两个不同的列,并将这些列添加到C#comboBox或中。ListBox这是我的代码:

SqlDataAdapter sda = new SqlDataAdapter("(select client_name from clients) UNION (select publication_name from publications)" + suffix, conn);
DataSet ds = new DataSet();
sda.Fill(ds);

我检查并获得了 5 行,其中dataset.Tables[0]2 行来自表publishers,3 行来自表clients

现在,在此之后,我编写了这段代码来将此获取的数据添加到comboBox.

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
   if (ds.Tables[0].TableName.ToString() == "clients" + suffix)
     comboBox1.Items.Add(ds.Tables[0].Rows[i]["clients" + suffix].ToString());
   if (ds.Tables[0].TableName.ToString() == "publications" + suffix)
     comboBox1.Items.Add(ds.Tables[0].Rows[i]["publications" + suffix].ToString());
}

不工作!请帮忙。

4

1 回答 1

0

得到这个工作!

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                    comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
            }
于 2013-07-30T05:49:22.147 回答