private void BtnSave_Click(object sender, EventArgs e) { long id = long.Parse((sender as Button).CommandArgument); using (StrPO_2018Entities db = new StrPO_2018Entities()) { var dbObject = editor.Data; dbObject.ID = id; db.Students.Attach(dbObject); db.Entry(dbObject).State = System.Data.Entity.EntityState.Modified; /*(from s in db.Students where s.ID == id select s).FirstOrDefault(); * if (dbObject == null) * { * ShowError(string.Format("Student with ID = {0} is not found", id)); * return; * } * dbObject.Name = txtName.Text; * dbObject.Surname = txtSurname.Text; * dbObject.Group = int.Parse(txtGroup.Text); * dbObject.Course = int.Parse(txtCourse.Text);*/ db.SaveChanges(); } Response.Redirect("MainForm.aspx"); }
private void BtnSave_Click(object sender, EventArgs e) { using (StrPO_2018Entities db = new StrPO_2018Entities()) { Student dbObject = editor.Data; db.Students.Add(dbObject); db.SaveChanges(); } Response.Redirect("MainForm.aspx"); }
private void loadData(long id) { using (StrPO_2018Entities db = new StrPO_2018Entities()) { var dbObject = (from s in db.Students where s.ID == id select s).FirstOrDefault(); if (dbObject == null) { ShowError(string.Format("Student with ID = {0} is not found", id)); return; } editor.Data = dbObject; } }