本帖最后由 elegant87 于 2010-04-09 09:16:11 编辑

解决方案 »

  1.   

    void CLoginDlg::OnLogin() 
    {
        // TODO: Add your control notification handler code here
        UpdateData(true);
        if(m_number.IsEmpty()||m_password.IsEmpty())
            AfxMessageBox("学号和密码都不能为空!");
        else
        {
            AdoConn.OnInitADOConn();
            CString strSQL="select count(*) as A from studentinfo where ID='"+m_number+"' and name='"+m_name+"'";
            AfxMessageBox(strSQL);
            _bstr_t bstrSQL(strSQL);
            _RecordsetPtr precordset=AdoConn.GetRecordSet(bstrSQL);//获取记录
      
                   if((long)(m_pRecordset->GetCollect("A"))>0 )          {
                flag=1;
                this->EndDialog(1);
            }
            else
            {
                    AfxMessageBox("学号或者密码错误!");
                m_number=" ";
                m_password=" ";
                UpdateData(FALSE);
            }
        }
        
    }
      

  2.   

    void CLoginDlg::OnLogin()  
    {
      // TODO: Add your control notification handler code here
      UpdateData(true);
      if(m_number.IsEmpty()||m_password.IsEmpty())
      AfxMessageBox("学号和密码都不能为空!");
      else
      {
      AdoConn.OnInitADOConn();
      CString strSQL="select count(*) as A from studentinfo where ID='"+m_number+"' and name='"+m_name+"'";
      AfxMessageBox(strSQL);
      _bstr_t bstrSQL(strSQL);
      _RecordsetPtr precordset=AdoConn.GetRecordSet(bstrSQL);//获取记录
       
      if((long)(m_pRecordset->GetCollect("A"))>0 ) {
      flag=1;
      this->EndDialog(1);
      }
      else
      {
      AfxMessageBox("学号或者密码错误!");
      m_number=" ";
      m_password=" ";
      UpdateData(FALSE);
      }
      }
        
    }
      

  3.   

    CString strSQL="select * from studentinfo where ID='"+m_number+"' and name='"+m_name+"'";strSQL = strSQL + _T("  select @@rowcount as RCount  ");//判断RCount>0,则表示有记录,否则表示没有记录!
      

  4.   

    用你上面的代码直接加上
    m_rs->RecordCount 看是否等于0.如果是0就不存在,不在就有记录
      

  5.   


    CString strSQL="select * from studentinfo where ID='"+m_number+"' and name='"+m_name+"'";
    我试了上面的方法,都没有成功。
    这句话有问题吗?
      

  6.   

    precordset->GetRecordCount() > 0
      

  7.   

    SQL Server2000,数据库连接成功的。
      

  8.   

    我输入了一个正确的ID和name,按照precordset->GetRecordCount() > 0和
    precordset->RecordCount>0 也不能登录成功。
      

  9.   


    void CLoginDlg::OnLogin() 
    {
        // TODO: Add your control notification handler code here
        UpdateData(true);
        if(m_number.IsEmpty()||m_password.IsEmpty())
            AfxMessageBox("学号和密码都不能为空!");
        else
        {
            AdoConn.OnInitADOConn();
            CString strSQL="select * from studentinfo where ID='"+m_number+"' and name='"+m_name+"'";
            AfxMessageBox(strSQL);
            _bstr_t bstrSQL(strSQL);
            _RecordsetPtr precordset=AdoConn.GetRecordSet(bstrSQL);//获取记录
             if(!precordset->IsEOF())  
            {
                flag=1;
                this->EndDialog(1);
            }
            else
            {
                    AfxMessageBox("学号或者密码错误!");
                m_number=" ";
                m_password=" ";
                UpdateData(FALSE);
            }
        }
        
    }
      

  10.   

    SQL Server2000 不支持 precordset->GetRecordCount() 属性
      

  11.   

    (!precordset->IsEOF())  也不行
    提示IsEOF' : is not a member of '_Recordset'
      

  12.   


    //下面GetRecordSet()函数的实现
    _RecordsetPtr & CAdoConnection::GetRecordSet(_bstr_t bstrSQL)  //执行查询
    {
     try
         {
            //连接数据库 如果Connection对象为空则重新连接数据库
            if(m_pConnection==NULL)
                  OnInitADOConn();
            //创建记录集对象
            m_pRecordset.CreateInstance(__uuidof(Recordset));
            //取得表中的记录
            m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockBatchOptimistic,adCmdText);
     }
         catch (_com_error e)
         {
             //异常  显示错误信息
             AfxMessageBox(e.Description());
          }
         return m_pRecordset;
    }
      

  13.   


    _bstr_t bstrSQL(strSQL);
     _RecordsetPtr precordset=AdoConn.GetRecordSet(bstrSQL);//获取记录
    precordset->MoveFirst();
    if(!precordset->IsEOF())  
    {
        flag=1;
        this->EndDialog(1);
    }
      

  14.   


    //改成这样就可以了,大家帮忙解释下吧。
    if(long(precordset->GetCollect(long(0)))>0)
    {
        flag=1;
        this->EndDialog(1);
    }
      

  15.   

    'IsEOF' : is not a member of '_Recordset'
    这是为什么呢?