Click here to Skip to main content
15,743,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am using ATL ( atldbcli.h) CCommand <CManualAccessor, CRowset, CNoMultipleResults> interfaces for my application. I need to count the number of records of a table.

I have tried executing (SELECT COUNT(*) from Table_Name) query but not able to retrieve the result.
CCommand <CManualAccessor, CRowset, CNoMultipleResults> atlAccessor;
    CDBPropSet commandProperties(GlobalSettings::GetDBType () == MSSQL ? DBPROPSET_ROWSET : ORAPROPSET_COMMANDS);//ORAPROPSET_COMMANDS);
    String newStatement;
    newStatement.Format (L" SELECT COUNT(*) FROM %s ",(const wchar_t*)m_tableInfo->GetName ());
    DBROWCOUNT rowCount;
    HRESULT hr = atlAccessor.CreateAccessor(nBindEntries, buffer, nBufferSize);

     if (S_OK == hr )
        DBROWCOUNT rowsAffected;
         hr = atlAccessor.Open (*session, (LPCWSTR)newStatement, &commandProperties,&rowsAffected,DBGUID_DEFAULT,false);
          if (S_OK == hr )
             DBCOUNTITEM dbCountItem=0 , dbRowCount =0;
            BYTE* data =  atlAccessor.GetBuffer();

Please help. Thanks in advance
Updated 24-Apr-11 20:10pm
cforbin 7-May-18 17:59pm    

I am needing to do several VERY similar queries (single row single column) using the exact same technologies... and running into similar problems. As of May 2018, you never received an answer. Did you solve the problem? If so, please update your question with the solution here! If not, I'll try to answer it here for posterity.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900