ComboBox Issue selectedIndexChanged

Apr 6 2020 3:24 AM
I have an Inventory Application with form of ProductMaster and I called Parent Category,Category and Sub Category to this form
All categories are saved in to one category table Named as tb_Category and each category and sub category saved as its own ID
I try to call the code like this
private void cmbMainCategory_SelectedIndexChanged(object sender, EventArgs e)
string conString = @"server=LAPTOP-UJIIOP3B; database=Inventory; uid=sa; password=praman1947;";
SqlConnection conn = new SqlConnection(conString);
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("select CategoryCode,CategoryName,ID from tb_Category where Flag='C' AND ID= '" + comboBox1.SelectedValue+ "' ", conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
cmbcategory.DisplayMember = "CategoryName";
cmbcategory.ValueMember = "CategoryCode";
cmbcategory.DataSource = ds.Tables[0];
catch (Exception ex)
//Exception Message
The value coming to 'cmbcategory' but the problem is the proper value coming after to selection of 'cmbMainCategory' and while loading the form and Main category selection showing the result of first row Main Category

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)