错误不知道在哪,急啊!
这个函数实现对输入的班级和姓名在数据库中对应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();
}