I have two comboboxs(name and category) and two tables(tbl_participant and tbl_category). I want to retrieve data from tlb_paticipant to cboName and tbl_category to cboCategory when the form load. Below is the code for retrieve tbl_paticipant to cboName, but I don't know how to retrieve another one. Make tow connection, command, DataReader object?
con = ConnectionDB.GetConnection();
string sql = "select * from tbl_Participant";
cmd = new SqlCommand(sql, con);
try
{
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
cboName.Items.Add(dr.GetValue(2).ToString());
}
cboName.SelectedIndex = 0;
cmd.Dispose();
con.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}