private void btnUpdate_Click(object sender, EventArgs e) { int id = int.Parse(dgv_Demo.CurrentRow.Cells["col_id"].Value.ToString()); demotbl demotb = db.demotbls.First(x => x.demoID == id); demotb.demoCode = txtLName.Text; db.SaveChanges(); MessageBox.Show("Successfull!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information); xulydata(); }
private void btnAdd_Click(object sender, EventArgs e) { try { demotbl demo = new demotbl() { demoCode = txtLastName.Text, demoName = txtFullName.Text }; db.demotbls.Add(demo); db.SaveChanges(); txtFullName.ResetText(); txtLastName.ResetText(); MessageBox.Show("Successfull!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information); xulydata(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Eror", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }