错误不知道在哪,急啊!

xidiancjw 2010-05-12 05:03:28
这个函数实现对输入的班级和姓名在数据库中对应ID的查询。先对班级进行判断,若班级存在则进一步对所输入学号进行
判断,若都存在则输出它们对应的ID号。
程序执行到星号处就直接跳到catch处,接着弹出"Unknown error 0x800A0E78"的消息框。
请高手指点一二,十分感谢!
int COHDCXDlg::SearchID()
{
UpdateData();
CoInitialize(NULL);
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
if(m_class=="") //外部输入为空
MessageBox("请输入班级");
else //输入不空,则在表中查找是否存在与输入相同的班名
{
CString claname,strSql;
strSql.Format("select cla_name from class_table");
BSTR bstrSQL=strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
_variant_t TheValue;
TheValue=m_pRecordset->GetCollect("cla_name");
//if(TheValue.vt!=VT_NULL)
claname=(char*)_bstr_t(TheValue);
if(claname==m_class) //如果表中存在与输入相等的值,进一步判断学号情况
{
if(m_name=="")
MessageBox("请输入姓名");
else //学号输入不空,则表中查找是否存在与输入相同的姓名
{
CString name,strSql;
strSql.Format("select stu_name from class_table");
BSTR bstrSQL=strSql.AllocSysString();
******** m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
_variant_t TheValue;
TheValue=m_pRecordset->GetCollect("stu_name");
//if(TheValue.vt!=VT_NULL)
name=(char*)_bstr_t(TheValue);
if(name==m_name) //姓名也存在,则查找相应的ID
{
CString strSql;
strSql.Format("select * from class_table where class_table.cla_name='%s' and class_table.stu_name='%s'",m_class,m_name);
BSTR bstrSQL=strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);

_variant_t TheValue;
TheValue=m_pRecordset->Fields->GetItem("ID")->Value;
//if(TheValue.vt!=VT_NULL)
stuID=TheValue.iVal;
return stuID;
}
else
m_pRecordset->MoveNext();
}
if(m_pRecordset->adoEOF)
MessageBox("姓名不存在");
return NULL;
}
}
else
m_pRecordset->MoveNext();
}
if(m_pRecordset->adoEOF)
MessageBox("班级不存在");
return NULL;
}
m_pRecordset->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
CoUninitialize();
}
...全文
59 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xidiancjw 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 visualeleven 的回复:]
debug调试。。。
[/Quote]
我调试了几个小时了,我在这个函数中三次用了m_pRecordset->Open(),况且是在第二个m_pRecordset->Open()处直接跳到了catch处,所以请教下是不是三次m_pRecordset->Open()的用法有问题啊
ljz888666555 2010-05-12
  • 打赏
  • 举报
回复
m_pRecordset你OPEN了两次,若要用先调用close方法再OPEN
kkmqj 2010-05-12
  • 打赏
  • 举报
回复
找到*号所在地了,不容易。
这个很可能是SQL语句书写问题吧。
你写成try,catch那种的。
Eleven 2010-05-12
  • 打赏
  • 举报
回复
debug调试。。。
wltg2001 2010-05-12
  • 打赏
  • 举报
回复
太长了,另外讨厌数据库编程!

4,011

社区成员

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

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