为什么我用下面的代码会出错:
_variant_t strSQL;
strSQL="select * from 密码表 where USER1='"+dlg.m_strUser+"' and PASWD1='"+dlg.m_strPass+"'";
pTheSet->Open(strSQL,pTheConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic, adCmdText);
if(pTheSet->GetRecordCount()==0)
{
MessageBox("用户名或密码错误");
pTheSet->Close();
return;
}为什么明明用户名和密码是错的,可它还是不执行if 里面的程序呢

解决方案 »

  1.   

    try{
    pTheSet->Open(strSQL,pTheConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic, adCmdText);
    if(pTheSet->adoEOF)
    {
    MessageBox("用户名或密码错误");
    if(pTheSet->GetState())
    pTheSet->Close();
    return;
    }
    catch(_com_error &e)
    {
    AfxMessageBox(e.ErrorMessage());
    }
      

  2.   

    catch(_com_error &e)
    {
    MessageBox("用户名或密码错误");AfxMessageBox(e.ErrorMessage());
    }
      

  3.   

    将RecordSet的CursorLocation属性设为adUseClient,当然设这个属性必须在表打开之前。如果你不设这个属性的话,那么RecordSet的RecordCount值是-1,除非你把整个记录集遍历一遍,才能得到记录数。