0
我有以下查询从两个不同的表中获取两个不同的列,并将这些列添加到C#中的comboBox
或ListBox
。 这是我的代码:从不同SQL表中获取数据并将其添加到组合框
SqlDataAdapter sda = new SqlDataAdapter("(select client_name from clients) UNION (select publication_name from publications)" + suffix, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
我检查,并在dataset.Tables[0]
,2从表从表客户有5行出版商和3。
现在,在此之后,我编写了此代码以将此提取的数据添加到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());
}
不工作!请帮忙。