//使用EF修改信息 private void button5_Click(object sender, EventArgs e) { using (var db = new TestEntities()) { using (var scope = new TransactionScope()) { var user = new Table_3 { ID = int.Parse(textBox1.Text), name = textBoxID.Text, sex = textBoxSex.Text, age = int.Parse(textBoxAge.Text) }; db.Table_3.Attach(user); var setEntry = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(user); setEntry.SetModifiedProperty("name"); setEntry.SetModifiedProperty("age"); setEntry.SetModifiedProperty("sex"); db.SaveChanges(); scope.Complete(); } } }
public ActionResult DeleteConfirmed(string id) { Table_3 table_3 = db.Table_3.Find(id); db.Table_3.Remove(table_3); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Models,footsize,city,quantity")] Table_3 table_3) { if (ModelState.IsValid) { db.Entry(table_3).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(table_3)); }
public ActionResult Edit([Bind(Include = "cars,carid,price,company")] Table_3 table_3) { if (ModelState.IsValid) { db.Entry(table_3).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.carid = new SelectList(db.Table_1, "Carid", "cars", table_3.carid); return(View(table_3)); }
public ActionResult Create([Bind(Include = "Models,footsize,city,quantity")] Table_3 table_3) { if (ModelState.IsValid) { db.Table_3.Add(table_3); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(table_3)); }
//使用EF删除指定ID的行 private void button4_Click(object sender, EventArgs e) { using (var db = new TestEntities()) { var t2 = new Table_3 { ID = int.Parse(textBoxDelID.Text) }; db.Table_3.Attach(t2); db.Table_3.Remove(t2); db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "cars,carid,price,company")] Table_3 table_3) { if (ModelState.IsValid) { db.Table_3.Add(table_3); return(RedirectToAction("Index")); } ViewBag.carid = new SelectList(db.Table_1, "Carid", "cars", table_3.carid); return(View(table_3)); }
// GET: Table_3/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Table_3 table_3 = db.Table_3.Find(id); if (table_3 == null) { return(HttpNotFound()); } return(View(table_3)); }
// GET: Table_3/Details/5 public ViewResult Details(int?id) { if (id == null) { return(View("Error")); } Table_3 table_3 = db.Table_3.FirstOrDefault(a => a.footsize == id); if (table_3 == null) { return(View("Error")); } return(View(table_3)); }
//使用EF新增信息 private void button3_Click(object sender, EventArgs e) { using (var db = new TestEntities()) { var t2 = new Table_3 { name = textBoxID.Text, sex = textBoxSex.Text, age = int.Parse(textBoxAge.Text) }; db.Table_3.Add(t2); db.SaveChanges(); } }
public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Table_3 table_3 = db.Table_3.Find(id); if (table_3 == null) { return(HttpNotFound()); } ViewBag.carid = new SelectList(db.Table_1, "Carid", "cars", table_3.carid); return(View(table_3)); }
public ViewResult DeleteConfirmed(int?id) { if (id == null) { return(View("Error")); } Table_3 table_3 = db.Table_3.FirstOrDefault(a => a.footsize == id); if (table_3 == null) { return(View("Error")); } db.Delete(table_3); return(NewMethod()); }