I have 2 combobox. I want to get data in second combobox on selection of first combobox but i am not getting the data in second combobox.
I am writing the code as following:
First Combobox=cmbCat
Second Combobox=cmbSCat1
private void GetCategory()
{
SqlDataAdapter da = new SqlDataAdapter("select * from Category ", con);
DataTable dt = new DataTable();
da.Fill(dt);
cmbCat.DataSource = dt;
cmbCat.DisplayMember = "Category";
cmbCat.ValueMember = "CId";
}
private void cmbCat_SelectedIndexChanged(object sender, EventArgs e)
{
string ik = cmbCat.SelectedText.ToString();
if (ik != "")
{
SqlDataAdapter da = new SqlDataAdapter("select SId,SUbCatName from SubCategory sc inner join Category c on sc.CId =c.CId where sc.CId=c.CId and c.Category='" + cmbCat.SelectedText.ToString() + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
cmbSCat1.DataSource = dt;
cmbSCat1.DisplayMember = "SubCatName";
cmbSCat1.ValueMember = "SId";
}
}
what is the error please suggest me.