Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // connect
            var conn = new ContosoEntities();

            // use the Department class to create a new Department obj
            Department d = new Department();

            // fill the properties of the new Department obj
            d.Name   = txtName.Text;
            d.Budget = Convert.ToDecimal(txtBudget.Text);

            // save the new object
            conn.Departments.Add(d);
            conn.SaveChanges();

            // redirect to the departments page
            Response.Redirect("departments.aspx");
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // connect
            var conn = new ContosoEntities();

            // use the Student class to create a new Department obj
            Student s = new Student();

            // fill the properties of the new Department obj
            s.LastName       = txtLastName.Text;
            s.FirstMidName   = txtFirstName.Text;
            s.EnrollmentDate = Convert.ToDateTime(txtEnrollment.Text);

            // save the new object
            conn.Students.Add(s);
            conn.SaveChanges();

            // redirect to the departments page
            Response.Redirect("students.aspx");
        }