private async void BtnAdd_Click(object sender, EventArgs e) { using (FormAddAccount frm = new FormAddAccount(new Account())) { if (frm.ShowDialog() == DialogResult.OK) { try { accountBindingSource.Add(frm.AccountInfo); db.Accounts.Add(frm.AccountInfo); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private async void BtnEdit_Click(object sender, EventArgs e) { Account obj = accountBindingSource.Current as Account; if (obj != null) { using (FormAddAccount frm = new FormAddAccount(obj)) { if (frm.ShowDialog() == DialogResult.OK) { try { accountBindingSource.EndEdit(); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }