Example #1
0
 public void btnSave_Click(object sender, EventArgs e)
 {
     mh.IDMH     = tbIDDDDDDDDDD.Text.Trim();
     mh.MA_HK    = tbMMH.Text.Trim();
     mh.TenMH    = tbMH.Text.Trim();
     mh.SoTC     = Convert.ToInt32(tbTC.Text.Trim());
     mh.LyThuyet = Convert.ToInt32(tbLT.Text.Trim());
     mh.ThucHanh = Convert.ToInt32(tbTH.Text.Trim());
     //mh.ThucHanh = Convert.ToInt32(tbTH.Text.Trim());
     using (MonhocEntities db = new MonhocEntities())
     {
         db.Entry(mh).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Example #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (MonhocEntities db = new MonhocEntities())
         {
             var entry = db.Entry(mh);
             if (entry.State == EntityState.Detached)
             {
                 db.Monhocs.Attach(mh);
             }
             db.Monhocs.Remove(mh);
             db.SaveChanges();
             MessageBox.Show("Deleted Successfully");
         }
     }
 }