//Initialize DataBase Connent
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance(_uuidof(Connection));
if (SUCCEEDED(hr))
{
m_pConnection->ConnectionString="File Name=my_database.udl";
m_pConnection->ConnectionTimeout=20;
hr=m_pConnection->Open("","","",adConnectUnspecified);
if (FAILED(hr))
{
AfxMessageBox("open fail!");
return TRUE;
}
}
else 
{
AfxMessageBox("createinstance of connection fail!");
return TRUE;
}
}
catch (_com_error e)
{
_bstr_t  bstrSource(e.Source());
_bstr_t  bstrDescription(e.Description());
AfxMessageBox(bstrSource+bstrDescription);
return TRUE;
}
//开始获取记录.....
HRESULT hr,rhr;
//定义记录集指针
_RecordsetPtr  pRentRecordset;
//实力化记录集指针
hr=pRentRecordset.CreateInstance(_uuidof(Recordset));
//判断创建记录集指针是否成功
if (FAILED(hr))
{
AfxMessageBox("CreateInstance of Recordset failed!\n\
   can't Initiate List control!");
return ;
}
CString strSql;
//定义_variant_t变量存储从数据库读取的字段
_variant_t  var;
CString strValue;
//int curItem=0;
//获取当前选择的索引
int cur=m_ctlUSER.GetCurSel();
if (cur==0)
//选择管理员登入时,则查找管理员表
strSql="SELECT M_Account,M_Paccword FROM management";
else
//选择教师登录时,则查找教师表
strSql="SELECT T_Account,T_Paccword FROM teacher"; try
{
//利用Open函数执行SQL命令,获得查询结果记录集
rhr=pRentRecordset->Open(_variant_t(strSql),
   m_pConnection.GetInterfacePtr(),
   adOpenDynamic,
   adLockOptimistic,
   adCmdText);
if (SUCCEEDED(rhr))
{
while(!pRentRecordset->adoEOF)
{
var=pRentRecordset->GetCollect((long)0);
if (var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
if ( m_sAccount==strValue )
{
var=pRentRecordset->GetCollect((long)1);
if (var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
if (m_sPassword==strValue)
{
MessageBox("OK");
break;
}
else 
{
MessageBox("密码不对");
break;
}
}
pRentRecordset->MoveNext();
}
if (pRentRecordset->adoEOF)
MessageBox("没有该用户");
}
else 
{
AfxMessageBox("Open recordset fail!");
}
}
catch( _com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return ;
}
pRentRecordset->Close();
pRentRecordset=NULL;
为什么运行到红色部分就出问题了??~
弹出如下错误:
Unhandled exception in SQL_Item.exe (KERNEL32.DLL): OxE06D7363: Microsoft C++ Exception.