Mike abban

Mike abban

  • NA
  • 10
  • 26k

populate checkedlistbox from db and mark some as checked

May 7 2014 5:02 AM
I have a windows form which loads all data from a table (tblMinistries) and displays it in a checklistbox. This work works correctly, now i have another table (tblNewministries) and i want all the items in the table (tblNewministries) to be checked automaticaly in the checkedlistbox when it is populated. table (tblNewministries) is a subset of table (tblMinistries)
Please help me out
 
code for populating the checkedlistbox
public void PopuMinistry()
{
SqlConnection conn = new SqlConnection("Data Source=USER-PC;Initial Catalog=PIWCDB;User ID=sa;Password=mike");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
string SqlDataPull = ("select Homecellname from tblministries order by Homecellname");
SqlCommand cmd = new SqlCommand(SqlDataPull);
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
SqlDataPull = dr[0].ToString();
cblMinistries.Items.Add(SqlDataPull);
}
dr.Close();
}