
使用者確認輸入後,呼叫 InsertObject 寫入資料庫,成功則重新整理清單。
private void cmdEdit_Click(object sender, EventArgs e)
{
DB_Employees emp = lstName.SelectedItem as DB_Employees;
if (emp == null) return;
using (dlgRecord dlg = new dlgRecord())
{
dlg.txtID.ReadOnly = true; // 主鍵不可修改
dlg.Employee = emp; // 傳入現有實體供編輯
if (dlg.ShowDialog(this) == DialogResult.OK)
{
using (MyORMFramework orm = CreateFramework())
if (orm.UpdateObject(emp) > 0) RefreshList(orm);
}
}
}
ReadOnly=true)。UpdateObject 內部呼叫 UpdateObjects,依關鍵欄位產生 WHERE 條件。