Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 780
  • 1.1k
  • 55.6k

C# Window Form Application

Oct 18 2023 11:44 AM

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();
            }         
        }


Answers (4)