我在一个登陆界面里进行注册时,向数据库插入新记录出错了,请问如何解决:
该数据表包括 uid(这是 identity 的),uname,upassword,unation ,ucity。对应对话框的Edit控件的变量为:
(其中uid不用输入,由数据库自动添加)
uname ==>> m_strID
upassword ==> m_strPW
unation ==>> m_strNation
ucity ==>> m_strCityCRecordSet类 为: CLoginSet
对话框类为: CRegisterDlg
下面是我的插入过程:void LoginDlg::OnRegister()
{
// TODO: Add your control notification handler code here
CDatabase ds;
CLoginSet *pLgnSet;
pLgnSet = new CLoginSet(&ds);
CRegisterDlg regDlg; if(regDlg.DoModal() == IDOK){
if(pLgnSet->IsOpen()) pLgnSet->Close();
if(!pLgnSet->Open()) regDlg.MessageBox("Can not open the database!");
if(pLgnSet->CanAppend()){
try{
pLgnSet->AddNew();
pLgnSet->m_uname = regDlg.m_strID;
pLgnSet->m_upassword = regDlg.m_strPW;
pLgnSet->m_unation = regDlg.m_strNation;
pLgnSet->m_ucity = regDlg.m_strCity;
if(!pLgnSet->IsBOF())
pLgnSet->MoveFirst();
pLgnSet->Requery();
pLgnSet->Update();
}
catch(CDBException e){
e.ReportError();
}
AfxMessageBox("Register sucessfully!");
}
else
AfxMessageBox("The database can not Append()!");
}
}
该数据表包括 uid(这是 identity 的),uname,upassword,unation ,ucity。对应对话框的Edit控件的变量为:
(其中uid不用输入,由数据库自动添加)
uname ==>> m_strID
upassword ==> m_strPW
unation ==>> m_strNation
ucity ==>> m_strCityCRecordSet类 为: CLoginSet
对话框类为: CRegisterDlg
下面是我的插入过程:void LoginDlg::OnRegister()
{
// TODO: Add your control notification handler code here
CDatabase ds;
CLoginSet *pLgnSet;
pLgnSet = new CLoginSet(&ds);
CRegisterDlg regDlg; if(regDlg.DoModal() == IDOK){
if(pLgnSet->IsOpen()) pLgnSet->Close();
if(!pLgnSet->Open()) regDlg.MessageBox("Can not open the database!");
if(pLgnSet->CanAppend()){
try{
pLgnSet->AddNew();
pLgnSet->m_uname = regDlg.m_strID;
pLgnSet->m_upassword = regDlg.m_strPW;
pLgnSet->m_unation = regDlg.m_strNation;
pLgnSet->m_ucity = regDlg.m_strCity;
if(!pLgnSet->IsBOF())
pLgnSet->MoveFirst();
pLgnSet->Requery();
pLgnSet->Update();
}
catch(CDBException e){
e.ReportError();
}
AfxMessageBox("Register sucessfully!");
}
else
AfxMessageBox("The database can not Append()!");
}
}
解决方案 »
- 被主管批评的不行了,下面的代码什么问题?DestroyWindow(hwndtemp)窗口后连主窗口都看不见了,但可以find主窗句柄,重新show后看不到啊
- VC 我想让一个RGN区域放大
- vc 有没有类似delphi 的tstringlist的对象
- 用domodel()生成一个对话框,关闭后,为何不能再重新生成了?
- 急:函数选择子难题
- 我在程序的App里头调用CMainFrame类可是为什么总是调用不正确,
- 急急急,我的软件要发布了,但我是第一次用VC写软件。有几个问题想问一下。
- treeview急!
- 怎么在word中插入另外一个word文件或者excel文件????
- 在普通的MFC工程中添加ATL简单对象,如何注册呢?
- 请问VC界面设计问题
- 求教一个非常简单的问题. c语言中exit(1) 的具体含义是什么..
==
但是我可以成功打开数据库,并且也是可以append,可以update的
后pLgnSet->Requery();