private void btSave_Click(object sender, EventArgs e) { var db = new StormEntities1(); var newStudent = db.Students.Find(this.std.Id); newStudent.Fullname = this.txtName.Text; newStudent.Code = this.txtCode.Text; newStudent.Class_id = (int)this.cbClass.SelectedValue; newStudent.Birthday = this.dtDob.Value; db.Entry(newStudent).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); this.Close(); MessageBox.Show("Edit student successfully"); }
private void btDelete_Click(object sender, EventArgs e) { var db = new StormEntities1(); if (MessageBox.Show("Are u sure ?", "Warning!!", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { for (int i = 0; i < this.lstStudent.SelectedRows.Count; i++) { var row = this.lstStudent.SelectedRows[i]; var item = (StudentView)row.DataBoundItem; try { Student student = db.Students.Find(item.Id); db.Students.Remove(student); db.SaveChanges(); } catch (Exception) { MessageBox.Show("Cannot delete student " + item); } } } loadStudent(); }
public FormEdit(Student std) { InitializeComponent(); this.std = std; db = new StormEntities1(); }