Hello Team,
Please in my window form application, am trying to load Category on the product entry form and save and my issues is category is not loading.

CLASS
public static void CBFill(string qry, ComboBox cb)
{
SqlCommand cmd = new SqlCommand(qry, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
cb.DataSource = dt;
cb.SelectedIndex = -1;
}
PRODUCT ENTRY FORM PAGE
private void frmProductAdd_Load(object sender, EventArgs e)
{
string qry = @"Select CategoryId 'id', CategoryName 'name' from tblCategory";
MainClass.CBFill(qry, cmbCategory);
if (id > 0)
{
cmbCategory.SelectedValue = catID;
LoadImage();
}
}
Amit MohantyPosted Oct 18, 2023, 1:57 PM
You have to pass both
displayMember, valueMember. Try like this:Emmmanuel FIADUFEPosted Oct 18, 2023, 3:44 PM
Thank you for your help, it is working now
Emmmanuel FIADUFEPosted Oct 18, 2023, 1:27 PM
Hello Amit, thank but, when I applied the changes the combobox started selecting only the category ID and when I remove the "id" leaving the name, the category name started coming MainClass.CBFill(qry,cmbCategory, " ", "name")" but when I tried to save the data into the database the category id in the product table become zero
Amit MohantyPosted Oct 18, 2023, 11:59 AM
Try like this: