How to delete data from checkboxlist as well as from the database at runtime?

By James J

Delete data from both checkboxlist control & database...

private void CheckboxListBind()
{

checkedListBox1.Items.Clear();
SqlConnection conn = new SqlConnection("connection string");
conn.Open();
SqlDataReader dr;
SqlCommand cmd = new SqlCommand("SELECT ename FROM employee", conn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
checkedListBox1.Items.Add(dr.GetValue(0).ToString());
}
conn.Close();
}

//Delete the data from checkboxlist as well as database...

SqlConnection conn = new SqlConnection("connection string");
conn.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM employee WHERE empid=5", conn);
cmd.ExecuteNonQuery();
conn.Close();

//here again call "CheckboxListBind" function for bind datea after deletion...

CheckboxListBind();

How to delete data from checkboxlist as well as from the database at runtime?  (749 Views)