0

2 つの異なるテーブルから 2 つの異なる列を取得し、その列をcomboBoxまたはListBoxC# に追加する次のクエリがあります。これは私のコードです:

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行、テーブルクライアントから 3 行の 5 行を取得しました。

この後、この取得したデータを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 に答える