LEATH
try{AfxMessageBox("提交成功");/*这里写入你确定后的程序*/CDialog::OnOK();}catch(CDBException e){AfxMessageBox("提交失败");}比方下面的SQL 添加记录的 程序按钮:void CAddRecord::OnBtnSubmit() {// TODO: Add your control notification handler code here// 添加记录UpdateData(true);CDatabase db;//打开数据库db.Open(NULL,FALSE,FALSE,"ODBC;DSN=odbcmfc;UID=root;PWD=");CString str_no = m_no;CString str_name = m_name;CString str_age = m_age;CString str_sex = m_sex;CString str_depart = m_depart;if (str_no == ""){AfxMessageBox("请填写学号");GetDlgItem(IDC_EDIT_NO)->SetFocus();return;}if (str_name == ""){AfxMessageBox("请填写姓名");GetDlgItem(IDC_EDIT_NAME)->SetFocus();return;}if (str_sex != "男" && str_sex != "女" && str_sex != ""){AfxMessageBox("性别只能填‘男’或‘女’");GetDlgItem(IDC_EEDIT_SEX)->SetFocus();return;}//插入新记录的SQL语句CString sql="insert into student (id,name, age,sex,depart)\values ('"+str_no+"','"+str_name+"', '"+str_age+"','"+str_sex+"','"+str_depart+"')"; try{db.ExecuteSQL(sql);AfxMessageBox("提交成功");CDialog::OnOK();}catch(CDBException e){AfxMessageBox("提交失败");}return;}