用VC操作SQL2000,采用ADO方式,连接数据库后打开库中的表,怎么样来获得表中数据记录的行数

解决方案 »

  1.   

    LPCSTR szSql=_T("select count(*) from 表名");
    m_pRs->Open(_bstr_t(szSql), (IDispatch*)m_pConn, adOpenDynamic,
    adLockOptimistic, adCmdText);
    if (!m_pRs->adoEOF)
    {
    _variant_t theValue;
    theValue = m_pRs->GetCollect(_variant_t((long)0)); 
    strValue = vartostr(theValue);  //这里就是行数了
    m_pRs->Close();
    return TRUE;
    }
    m_pRs->Close();
      

  2.   

    给count(*)起个别名,就可以用这个别名访问这个值了