When I choose a value in ComboBox. How can I use them to query SQL??
I tried
private void cmb1_SelectedIndexChanged(object sender, EventArgs e)
{
string select = this.cmb1.GetItemText(this.cmb1.SelectedItem);
cm1 = new SqlCommand("select VS from DATABASE where ROUND=select", con);
ap = new SqlDataAdapter(cm1);
ds = new System.Data.DataSet();
ap.Fill(ds, "DATABASE");
cmb2.DataSource = ds.Tables[0];
cmb2.DisplayMember = "VS"; // show in combobox2
}
I want to use the variable select to query but it doesn't work.
cmb2andcombobox2same? You wanna use selected value incombobox2as a parameter in your sql query instead? Can you please be more specific? By the way, yourwhere ROUND=selectwon't work if you try to queryselectas a text. You need to usewhere ROUND = 'select'in such a case.selectis a terrible name for a variable.