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");
-
- comboBox2.DataSource = ds.Tables["wagon"];
- comboBox2.DisplayMember = "id_w";
- comboBox2.ValueMember = "id_w";