private void btnAdd_Click(object sender, EventArgs e) { frmPatientEditor editor = new frmPatientEditor(); if (editor.ShowDialog() == DialogResult.OK) { try//每个try内部的方法都是关键,保存数据的操作,下同不再赘述 { this.pTable.Rows.Add(editor.pRow); this.pAdapter.Update(this.pTable); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnEdit_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.Name)) { return; } var selRow = this.pTable.First(x => x[1].ToString() == this.selectedName); frmPatientEditor editor = new frmPatientEditor(selRow); if (editor.ShowDialog() == DialogResult.OK) { try { this.pAdapter.Update(selRow); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }