private void btn_Update_Click(object sender, EventArgs e) { using (Student_DBEntities db = new Student_DBEntities()) { var Stud = db.tbl_Student.Find(Convert.ToInt32(tb_ID.Text)); if (Stud != null) { Stud.Name = tb_Name.Text; Stud.Mobile_No = Convert.ToInt64(tb_Mobile_No.Text); Stud.City = cmb_City.Text; Stud.DOB = dtp_DOB.Value; if (rbtn_male.Checked) { Stud.Gender = rbtn_male.Text; } else { Stud.Gender = rbtn_Female.Text; } db.SaveChanges(); MessageBox.Show("Information Deleted Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); } else { MessageBox.Show("Invalid Student ID Can't Delete", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btn_Delete_Click(object sender, EventArgs e) { using (Student_DBEntities db = new Student_DBEntities()) { var Stud = db.tbl_Student.Find(Convert.ToInt32(tb_ID.Text)); if (Stud != null) { db.tbl_Student.Remove(Stud); db.SaveChanges(); MessageBox.Show("Information Deleted Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); } else { MessageBox.Show("Invalid Student ID Can't Delete", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btn_Save_Click(object sender, EventArgs e) { string gender = null; if (tb_ID.Text != "" && tb_Name.Text != "" && tb_Mobile_No.Text != "" && cmb_City.Text != "" && (rbtn_male.Checked || rbtn_Female.Checked)) { using (Student_DBEntities db = new Student_DBEntities()) { if (rbtn_male.Checked) { gender = rbtn_male.Text; } else { gender = rbtn_Female.Text; } db.tbl_Student.Add(new tbl_Student() { Id = Convert.ToInt32(tb_ID.Text), Name = tb_Name.Text, Mobile_No = Convert.ToInt64(tb_Mobile_No.Text), City = cmb_City.Text, DOB = dtp_DOB.Value, Gender = gender } ); db.SaveChanges(); MessageBox.Show("Information Save Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); Autoincreament(); ClearControls(); } } else { MessageBox.Show("1st Fill All The Fields", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }