예제 #1
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     model.Id          = Convert.ToInt32(txtId.Text.Trim());
     model.Name        = txtName.Text.Trim();
     model.VehicleType = txtVehicleType.Text.Trim();
     model.Purpose     = txtPurpose.Text.Trim();
     using (EFDBEntities db = new EFDBEntities())
     {
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
     }
     Clear();
     DisplayDataGridview();
     MessageBox.Show("Record Succcessfully Updated..");
 }
예제 #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure To Delete this Record?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (EFDBEntities db = new EFDBEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Rockets.Attach(model);
             }
             db.Rockets.Remove(model);
             db.SaveChanges();
             DisplayDataGridview();
             Clear();
             MessageBox.Show("Record Deleted Successfully");
         }
     }
 }