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

            //use department class of the new department object
            Department d = new Department();

            d.Name   = txtName.Text;
            d.Budget = Convert.ToDecimal(txtBudget.Text);

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

            //redirect to department page
            Response.Redirect("departments.aspx");
        }
Пример #2
0
        protected void Savebtn_Click(object sender, EventArgs e)
        {
            //connect
            var conn = new ContosoEntities();

            //use the s class of the new department object
            Student d = new Student();

            d.FirstMidName = txtFirstName.Text;
            d.LastName     = txtLastName.Text;

            d.EnrollmentDate = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", null);

            //save the new object into the database
            conn.Student.Add(d);
            conn.SaveChanges();

            //redirect to department page
            Response.Redirect("student.aspx");
        }
Пример #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            var conn = new ContosoEntities();

            //use the department class to creat a new department object
            Student s = new Student();

            //fill the properties of the new department object
            s.FirstMidName   = txtLastName.Text;
            s.LastName       = txtFirstName.Text;
            s.EnrollmentDate = Convert.ToDateTime(txtEnrollemntDate.Text);


            //Save the new object to the database
            conn.Students.Add(s);
            conn.SaveChanges();

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