public ActionResult Edit([Bind(Include = "Id,CustomerFirstName,CustomerLastName,Line1,Line2,City,State,Country,ZipCode")] CustomerData customerData) { if (ModelState.IsValid) { db.Entry(customerData).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerData)); }
private void btnSave_Click(object sender, EventArgs e) { if (this.address.AddressId == 0) { ctx.Addresses.Add(this.address); ctx.SaveChanges(); this.Close(); } ctx.Entry(this.address).CurrentValues.SetValues(this.address); ctx.SaveChanges(); this.Close(); }
private void updatebtn_Click(object sender, EventArgs e) { try { var update = ctx.Addresses.Find(drow.Cells["AddressID"].Value); update.Street = streettxt.Text; update.City = citytxt.Text; update.State = statetxt.Text; update.Zip = ziptxt.Text; ctx.Entry(update).State = Microsoft.EntityFrameworkCore.EntityState.Modified; //update any changes made ctx.SaveChanges(); System.Windows.Forms.Application.OpenForms.OfType <CustomerRead>().FirstOrDefault().getData(); //refreshes main form this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }