//This is the event. When the user clicks submit, it will do the following: protected void btnSubmit_Click(object sender, EventArgs e) { DBoperations DB = new DBoperations(); string username = UserName_Form.Text; string notes = "Tester"; int SID = DB.GetStudentID(username); int ATID = Convert.ToInt32(TimeSlots_Form.SelectedValue); Boolean value = DB.CreateAppointment(ATID, SID, notes); string cs = WebConfigurationManager.ConnectionStrings["localConnection"].ConnectionString; SqlConnection con = new SqlConnection(cs); int APID = 0; try { string selectSQL = "Select APID FROM KBS_APPOINTMENTS WHERE ATID=" + ATID + ";"; SqlCommand com = new SqlCommand(selectSQL, con); string setNonValid = "UPDATE KBS_ADVISOR_TIMES SET Valid=0 WHERE ATID=" + ATID + ";"; SqlCommand edit = new SqlCommand(setNonValid, con); con.Open(); APID = (int)com.ExecuteScalar(); edit.ExecuteNonQuery(); } catch (Exception err) { err.ToString(); } finally { con.Close(); } foreach (ListItem row in Reason_Form.Items) { if (row.Selected == true) { int reasons = Convert.ToInt32(row.Value); DB.MatchReasonsToAppointment(reasons, APID); } } DB = null; }