Here is a Sample Code For Class ComboBox
public DataTable classComboBox()
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection("your connection string");
SqlCommand comm = new SqlCommand("Select * from class", conn);
SqlDataAdapter SDA = new SqlDataAdapter(comm);
SDA.SelectCommand = comm;
SDA.Fill(dt);
return dt;
}
Here is a sample Code For category ComboBox
public DataTable categoryComboBox()
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection("your connection string");
SqlCommand comm = new SqlCommand("Select * from category ", conn);
SqlDataAdapter SDA = new SqlDataAdapter(comm);
SDA.SelectCommand = comm;
SDA.Fill(dt);
return dt;
}
And You Can Call Into Form Like This.......
public void FillClasscombox()
{
DataTable dt = classComboBox();
yourClassCombobox.DataSource = dt;
yourClassCombobox.DisplayMember = "className";
yourClassCombobox.ValueMember = "classId";
}
Here Your Calling Method Of catogry
public void FillCatogrycombox()
{
DataTable dt = categoryComboBox();
yourClassCombobox.DataSource = dt;
yourClassCombobox.DisplayMember = "category";
yourClassCombobox.ValueMember = "categoryId";
}
Finaly call FillClasscombox() and FillCatogrycombox() into the Constructor
like this
public yourconstructor()
{
InitializeComponent();
FillClasscombox();
FillCatogrycombox();
}