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

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.
C++
CCommand <CManualAccessor, CRowset, CNoMultipleResults> atlAccessor;
   
    CDBPropSet commandProperties(GlobalSettings::GetDBType () == MSSQL ? DBPROPSET_ROWSET : ORAPROPSET_COMMANDS);//ORAPROPSET_COMMANDS);
    SetCommandProperties(commandProperties);
    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();
            MessageBox(NULL,L"",L"",S_OK);
         }
     }

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

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