CString strSQL;
long i;
CRecordset rs(&m_db); strSQL.Format( _T("SELECT * FROM LoginTable where user='%s' and password='%s'"),m_sEdit_Content,m_pEdit_Content );
rs.Open(CRecordset::dynaset,strSQL);
i=rs.GetRecordCount();
我数据库有两条记录,为什么总是返回0呢?MFCodbc数据库

解决方案 »

  1.   


    sqlstr.Format(_T("select * from LoginTable"));
    m_UserRecordSet.Open(CRecordset::snapshot,sqlstr,CRecordset::none);
    int n=m_UserRecordSet.GetRecordCount();
    还是为零。。
      

  2.   

    [LoginTable] 对表名加个[]试下.
      

  3.   

    sqlstr.Format(_T("select * from [LoginTable]"));
    还是一样为零
      

  4.   

    看看msdn就可以了:
    The record count is maintained as a "high water ," the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count. 
     
    意思就是说,先要滚动一下
      

  5.   

    CString sqlstr;
    sqlstr.Format(_T("select * from [LoginTable] where user='%s'"),m_sEdit_Content);

    m_UserRecordSet.Open(CRecordset::snapshot,sqlstr,CRecordset::none);

    if(!m_UserRecordSet.IsBOF())
    m_UserRecordSet.MoveFirst(); while(!m_UserRecordSet.IsEOF())
    m_UserRecordSet.MoveNext(); int n=m_UserRecordSet.GetRecordCount();
    如果把where去掉可以正确计算记录数了,但是,加入where又老是为零了。