UpdateData(1); CString strSql;
strSql.Format("select* from client where phonenum='%s' and IDcardnum='%s'",m_sjh,m_sfz);//m_sjh 手机号,m_sfz 身份证号
_bstr_t strSQL=strSql;
try
{ TESTHR(m_pRs.CreateInstance(__uuidof(Recordset)));

m_pRs->Open("client",_variant_t((IDispatch*)m_pCon,true),adOpenKeyset,adLockOptimistic,adCmdTable);

m_pCon->Execute(strSQL,NULL,adCmdText);
//如果没有找到记录
if(m_pRs->EndOfFile && m_pRs->FirstOfFile)
{
   AfxMessageBox(_T("您输入的手机号或身份证号错误,请重新输入"));
}
     else
{

strSql.Format("delete from client where phonenum='"+m_sjh+"' and IDcardnum='"+m_sfz+"'");
    _bstr_t strSQL=strSql;
    m_pCon->Execute(strSQL,NULL,adCmdText);
    }
为什么即使没有找到记录if中的语句也不执行,是不是我的if条件不对?
应该怎么判断?

解决方案 »

  1.   

    if(!m_pRs->EndOfFile)
    {
    strSql.Format("delete from client where phonenum='"+m_sjh+"' and IDcardnum='"+m_sfz+"'");
        _bstr_t strSQL=strSql;
        m_pCon->Execute(strSQL,NULL,adCmdText);
    }
         else
    {
       AfxMessageBox(_T("您输入的手机号或身份证号错误,请重新输入"));
        }
      

  2.   

    不行啊
    只执行else语句,而且不论输入的手机号存在还是不存在都执行else
      

  3.   

    你写的开始就有问题
    UpdateData(true);
    //构造sql语句
    CString strSql;
    if(m_strSjh !=""&&m_strSfz != "")
    {
        strSql.Format("select* from client where phonenum='%s' and IDcardnum='%    s'",m_strsjh,m_strsfz);elseif(m_strSjh !="" && m_strSfz =="")
    {
        strSql.Format("("select* from client where phonenum='%s' ,m_strSjh
    }
    elseif(m_strSjh =="" && m_strSfz != "")
    {
       strSql.Format("("select* from client where IDcardnum='%s'",m_strSfz );
    }
    else
    {
         strSql.Format("select * from  client")
    }
    m_pRs->close();
    try
    {
    m_pRs->Open(strSql,_variant_t((IDispatch*)m_pCon,true),adOpenDynamict,adLockOptimistic,adCmdText);
    m_pCon->Execute(strSQL,NULL,adCmdText);//这一句根本不需要,你画蛇添足了if(m_pRs->EndOfFile && m_pRs->FirstOfFile)
    {
       AfxMessageBox(_T("您输入的手机号或身份证号错误,请重新输入"));
    }
         else
    {

    strSql.Format("delete from client where phonenum='"+m_sjh+"' and IDcardnum='"+m_sfz+"'");
        _bstr_t strSQL=strSql;
        m_pCon->Execute(strSQL,NULL,adCmdText);
        }