2 回答

TA貢獻1936條經(jīng)驗 獲得超7個贊
try
{
AfxMessageBox("提交成功");
/*這里寫入你確定后的程序*/
CDialog::OnOK();
}
catch(CDBException e)
{
AfxMessageBox("提交失敗");
}
比方下面的SQL 添加記錄的 程序按鈕:
void CAddRecord::OnBtnSubmit()
{
// TODO: Add your control notification handler code here
// 添加記錄
UpdateData(true);
CDatabase db;//打開數(shù)據(jù)庫
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("請?zhí)顚憣W(xué)號");
GetDlgItem(IDC_EDIT_NO)->SetFocus();
return;
}
if (str_name == "")
{
AfxMessageBox("請?zhí)顚懶彰?quot;);
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;
}

TA貢獻1865條經(jīng)驗 獲得超7個贊
話說用C++編寫免不了MFC光工程框架就很大了!
Win32 SDK寫吧!
加上#include"windows.h"
寫上主函數(shù)WinMain(.....)
至于如何寫,MSDN上面很清楚,祝你好運!
if(IDOK==MessageBox("確認(rèn)當(dāng)前操作么?","詢問...",MB_YESNO))
{
MessageBox("你確認(rèn)的...");
}
else
{
MessageBox("你取消了...");
}
- 2 回答
- 0 關(guān)注
- 250 瀏覽
添加回答
舉報