protected void btnSave_Click(object sender, EventArgs e) { //connect the db var conn = new ContosoEntities(); //use the Department class to create a new Department object from department.cs Department d = new Department(); //fill the properties of the new department object d.Name = txtName.Text; d.Budget = Convert.ToDecimal(txtBudget.Text); //save a new object to db conn.Departments.Add(d); conn.SaveChanges(); //redirect to the department page Response.Redirect("departments.aspx"); }
// When save button is clicked connect to DB and save the values to DB protected void btnSave_Click(object sender, EventArgs e) { //connect the db var conn = new ContosoEntities(); //use the Student class to create a new Student object from student.cs Student s = new Student(); //fill the properties of the new student object s.FirstMidName = txtFirstName.Text; s.LastName = txtLastName.Text; s.EnrollmentDate = Convert.ToDateTime(eTxtDate.Text); //save a new object to db conn.Students.Add(s); conn.SaveChanges(); //redirect to the department page Response.Redirect("students.aspx"); }