Two ComboBoxes - cmbSupplier and cmbProduct
I want to fill cmbSupplier with supplier names from a table
when I select a value from cmbSupplier depending on the name selected Products with the supplier name should fill cmbProduct
private void frmAddOrder_Load(object sender, EventArgs e) {
SqlCommand cmd = new SqlCommand("SELECT sup_name from tbl_supplier",con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
cmbSupplier.Items.Add(dr["sup_name"].ToString());
}
dr.Close();
}
this is the code I use to fill cmbSupplier
I tried using this code to fill cmbProducts but all I get is an error
private void cmbSupplier_SelectedIndexChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT Product_Name from tbl_SupplierItems WHERE supplier_name'" + cmbSupplier.Text + "%'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
cmbProduct.Items.Add(dr["Product_Name"].ToString());
}
dr.Close();
}