2 回答
TA贡献1936条经验 获得超6个赞
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;
}
TA贡献1865条经验 获得超7个赞
话说用C++编写免不了MFC光工程框架就很大了!
Win32 SDK写吧!
加上#include"windows.h"
写上主函数WinMain(.....)
至于如何写,MSDN上面很清楚,祝你好运!
if(IDOK==MessageBox("确认当前操作么?","询问...",MB_YESNO))
{
MessageBox("你确认的...");
}
else
{
MessageBox("你取消了...");
}
- 2 回答
- 0 关注
- 171 浏览
添加回答
举报