错误不知道在哪,急啊!
这个函数实现对输入的班级和姓名在数据库中对应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();
}
判断,若都存在则输出它们对应的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();
}
...全文
相关推荐
我已经写了我的问题的代码,但是仍然有一些错误,我不知道该如何解决。 Pleaseeee帮忙! ! 1个
同时,“我不知道如何解决它们”表达了对解决问题的困惑,这是学习编程过程中的一个关键挑战。在标签中提到的“Python2.7”,意味着问题可能与这个特定版本的 Python 相关。
知道和不知道作文.doc
例如,母亲明明知道孩子的一些错误行为,如打碎花瓶、弄脏新衣,甚至故意调皮,但她选择不说破,而是以“不知道”来包容和保护孩子的天真。
一个简单但不知道错误在哪里的程序,找了好几天的资料都不知道,请各位帮帮忙
**运行时错误**:在CLIPS中,运行时错误可能是由于事实声明不当、规则冲突或槽类型不匹配等原因引起的。检查槽的类型与赋给它们的值是否相符。4.
yerror:helps有助于您知道您遇到了错误
恐怖知道为什么会出错会有所帮助。用法首先,要求我在哪里可能引发错误: import YError from 'yerror' ; 然后,发出带有奖励的错误:参数! function doSomethi
你不知道我为什么离开你.doc
【知识点解析】这首歌《你不知道我为什么离开你》是由王力宏作词并作曲的一首情感丰富的歌曲,歌词中的主题围绕着爱情中的离别与内心的纠结。


数据库
