Look ay comments in code.
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
String strConnString = ConfigurationManager.ConnectionStrings["facultylogConnectionString"].ConnectionString;
String strQuery = "Insert into selections (subname, selections) VALUES (@subname, @selections) where subname= @subname ";
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
cmd.Parameters.AddWithValue("@subname", DropDownList5.SelectedValue);
string var = string.Empty;
for (int i = 0; i < CheckBoxList1.Items.Count - 1; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
var += CheckBoxList1.Items[i].Text.ToString() + ",";
}
}
cmd.Parameters.AddWithValue("@selections", var);
cmd.Parameters.Clear();
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}