protected void btnAdd_Click(object sender, EventArgs e) { try { using (DefaultConnectionEF db = new DefaultConnectionEF()) { //get the values needed Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); Int32 CourseID = Convert.ToInt32(ddlCourse.SelectedValue); //populate the new enrollment object Enrollment objE = new Enrollment(); objE.StudentID = StudentID; objE.CourseID = CourseID; //save db.Enrollments.Add(objE); db.SaveChanges(); //refresh GetStudent(); } } catch (System.Data.SqlClient.SqlException e3) { Server.Transfer("/error.aspx", true); } catch (System.Data.Entity.Core.EntityException e3) { Server.Transfer("/error.aspx", true); } }
protected void btnAdd_Click(object sender, EventArgs e) { try { using (DefaultConnectionEF db = new DefaultConnectionEF()) { //get the values needed Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]); Int32 CourseID = Convert.ToInt32(ddlCourse.SelectedValue); //populate the new enrollment object Enrollment objE = new Enrollment(); objE.StudentID = StudentID; objE.CourseID = CourseID; //save db.Enrollments.Add(objE); db.SaveChanges(); //refresh GetStudent(); } } catch { Response.Redirect("/error.aspx"); } }