Ado.net组合框问题 [英] Ado.net combobox problem
本文介绍了Ado.net组合框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从火车的第一个组合框id中选择,在第二个组合框中给我一辆火车的货车(一辆货车的号码)我做了一个数据库:第一个表存储了火车id,第二个表存放了货车id + id火车外键我尝试了这个代码和它的工作但是当我选择另一个id它不会改变旅行车组合框结果
我尝试过什么:
I wanna select from first combobox id of a train and in the second combobox give me the wagon that train has (number of a wagon ) I did a database: that first table stored the train id and the second table stored wagon id + id train foreign key i tried this code and its work but when i choose another id it doesn't change the wagon combobox result
What I have tried:
adapter = new SqlDataAdapter("select * from train", cn);
SqlCommand cmd = new SqlCommand("select * from train", cn);
cmd.Parameters.Clear();
adapter.Fill(ds, "train");
comboBox1.DataSource = ds.Tables["train"];
comboBox1.DisplayMember = "id";
comboBox1.ValueMember = "id";
adapter = new SqlDataAdapter("select id_w from wagon where id='" + comboBox1.SelectedValue + "'", cn);
adapter.Fill(ds, "wagon");
// adapter1.SelectCommand.Parameters.Clear();
comboBox2.DataSource = ds.Tables["wagon"];
comboBox2.DisplayMember = "id_w";
comboBox2.ValueMember = "id_w";
推荐答案
您好,
ComboBox.SelectedIndexChanged 事件。
你必须通过train_id in train_SelectedIndexChanged事件。
ie,
Hello,
ComboBox.SelectedIndexChanged event occurs when the SelectedIndex property has changed.
You have to pass train_id in train_SelectedIndexChanged event.
i.e.,
private void train_SelectedIndexChanged(object sender,System.EventArgs e)
{
//Load the wagon_details and populate in combobox.
}
谢谢
thanks
这篇关于Ado.net组合框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文