protected void getDepartments() { // connect to the db var conn = new ContosoEntities(); // run the query using LINQ var Departments = from d in conn.Departments select d; // display query result in gridview grdDepartments.DataSource = Departments.ToList(); grdDepartments.DataBind(); }
protected void getStudents() { // connect to the db var conn = new ContosoEntities(); // run the query using LINQ var Students = from s in conn.Students select s; // display query result in gridview grdStudents.DataSource = Students.ToList(); grdStudents.DataBind(); }
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"); }