2 つの異なるテーブルから 2 つの異なる列を取得し、その列をcomboBox
またはListBox
C# に追加する次のクエリがあります。これは私のコードです:
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());
}
動かない!助けてください。