ADO MFC添加和修改的疑惑

一人在外 2012-08-28 11:13:14
void CINHADlg::OnBnClickedButton1() //添加
{
// TODO: 在此添加控件通知处理程序代码
CString str;

try
{
theApp.pRst->Close(); //在此处出错,前面打开过pRst。
theApp.pRst->Open("select * from EmInfo",theApp.pConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
theApp.pRst->AddNew();
FieldsPtr fieldsPtr;
fieldsPtr=theApp.pRst->Fields;

GetDlgItem(IDC_EDIT1)->GetWindowText(str);
fieldsPtr->Item["EmNu"]->Value=(_bstr_t)str;


theApp.pRst->Update();
MessageBox("添加成功");
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
}


void CINHADlg::OnBnClickedButton3()    //修改人员信息函数
{
CString str,sql;


try
{
theApp.pRst->Close();
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
sql.Format(_T("select * from EmInfo where EmNu = '%s'"),str);
theApp.pRst->Open((LPCSTR)sql,theApp.pConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
FieldsPtr fieldsPtr;
fieldsPtr=theApp.pRst->Fields;
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
fieldsPtr->Item["EmNu"]->Value=(_bstr_t)str;


theApp.pRst->Update();
MessageBox("添加成功");
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}*/
}

以上两个函数有错误,求大神鉴定错在何处。
...全文
80 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
一人在外 2012-08-29
  • 打赏
  • 举报
回复
程序基本完成了:http://download.csdn.net/detail/fengzhileiyi/4533047
有兴趣的可以看下
一人在外 2012-08-29
  • 打赏
  • 举报
回复
这次还是低级的错误。。。数据库内容改了之后,我把代码里的sql语句通改了一下,结果出现了遗漏。。。不过三楼的异常捕获很有用处,建议大家在做程序的时候做好异常处理,在出现错误的时候可以省很多的时间。
BombZhang 2012-08-28
  • 打赏
  • 举报
回复
关闭记录集前先判断,否则记录集未打开时执行Close会出错:
if(theApp.pRst!=NULL && theApp.pRst->State)
theApp.pRst->Close();
傻X 2012-08-28
  • 打赏
  • 举报
回复
听说楼主已把问题解决了。

大家都为楼主出过力

求楼主下次结贴的时候分享下问题,谢谢
一人在外 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

异常捕获改成这样试试
C/C++ code
try
{
//你的ADO代码
}
catch (_com_error& e)
{
CString strMsg;
strMsg.Format(_T("错误描述:%s\n错误消息%s"),
(LPCTSTR)e.Description(),
(LPCTSTR)e.ErrorMessage());
AfxMe……
[/Quote]显示至少一个参数没有被指定值
zyq5945 2012-08-28
  • 打赏
  • 举报
回复
异常捕获改成这样试试
try
{
//你的ADO代码
}
catch (_com_error& e)
{
CString strMsg;
strMsg.Format(_T("错误描述:%s\n错误消息%s"),
(LPCTSTR)e.Description(),
(LPCTSTR)e.ErrorMessage());
AfxMessageBox(strMsg);
}

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧