/** *<summary> * This method gets the students data from the DB *</summary> * * @method GetStudents * @returns {void} */ protected void GetStudents() { // connect to EF using (DefaultConnectionYd db = new DefaultConnectionYd()) { // query the Students Table using EF and LINQ var Students = (from allStudents in db.Students select allStudents); //bind the result to the GridView //StudentsGridView.DataSource = Students.ToList(); //StudentsGridView.DataBind(); } }
protected void SaveButton_Click(object sender, EventArgs e) { // Use EF to connect to the server using (DefaultConnectionYd db = new DefaultConnectionYd()) { //use the Student model to create a new student object and //save a new record Game newStudent = new Game(); //add form data to the new student record //use LINQ to ADO.NET to add / insert new student into the database //db.Students.Add(newGame); //save our changes db.SaveChanges(); //redirect back to the updated Student page Response.Redirect("~/Game.aspx"); } }