コード例 #1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                using (ContosoEntitiesEF conn = new ContosoEntitiesEF())
                {
                    Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);
                    Int32 StudentID = Convert.ToInt32(ddlStudent.SelectedValue);

                    Enrollment objE = new Enrollment();

                    objE.StudentID = StudentID;
                    objE.CourseID = CourseID;

                    conn.Enrollments.Add(objE);
                    conn.SaveChanges();

                    GetCourse();
                }
            }
            catch (Exception g)
            {
                Response.Redirect("/error.aspx");
            }
        }
コード例 #2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            using (ContosoEntities conn = new ContosoEntities())
            {
                Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);
                Int32 StudentID = Convert.ToInt32(ddlStudent.SelectedValue);

                Enrollment objE = new Enrollment();

                objE.StudentID = StudentID;
                objE.CourseID = CourseID;

                conn.Enrollments.Add(objE);
                conn.SaveChanges();

                GetCourse();
            }
        }