Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. RecordCount Property return me -1?

RecordCount Property return me -1?

Scheduled Pinned Locked Moved Database
sharepointcomhelpquestionannouncement
3 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anju
    wrote on last edited by
    #1

    Hi,All RecordCount Property giving me -1 value Please read my code and give me where i am doing wrong; and also please comment on my Code(if their any mistakes) Thanks in Advance.. /////////////This is my code To Test the Function//////////////////// _RecordsetPtr pRst; CString strTemp; pRst.CreateInstance(__uuidof(Recordset)); pRst=GetData(1); if(pRst!=NULL) { int nCount=(int)pRst->RecordCount; strTemp.Format("%d",nCount); AfxMessageBox(strTemp); } else { AfxMessageBox("Recordset null"); } pRst.Close(); pRst.Release(); //////////////////////////////////// ///////////////////This is my funtion which will return me Recordset object/////////// _RecordsetPtr GetData(int nType) { CString strType; strType.Format("%d",nType); try { //COM Library Initialization if(FAILED(::CoInitialize(NULL))) { //Log error return NULL; }//if(FAILED(::CoInitialize(NULL)) //Open the Connection m_hr=m_pConnection.CreateInstance(__uuidof(Connection)); if(FAILED(m_hr)) { ::CoUninitialize(); //Log error return NULL; } m_strCnnString=GetConnectionString();//It will give me the Connection String _bstr_t cnnString(m_strCnnString); _bstr_t bstrEmpty(""); m_hr=m_pConnection->Open(cnnString,bstrEmpty,bstrEmpty,adConnectUnspecified); if(FAILED(m_hr)) { m_pConnection.Release(); ::CoUninitialize(); //Log error return NULL; } //Get the Command objet m_hr=m_pCommand.CreateInstance(__uuidof(Command)); if(FAILED(m_hr)) { m_pConnection->Close(); m_pConnection.Release(); ::CoUninitialize(); //Log error return NULL; } m_pCommand->ActiveConnection=m_pConnection; m_pCommand->CommandText="Sp_GetData"; m_pCommand->CommandType=adCmdStoredProc; //Append the Parameters to Command object //Type Parameter m_pParam=m_pCommand->CreateParameter(_bstr_t("Type"),adInteger,adParamInput,4,_variant_t(strType)); m_pCommand->Parameters->Append(m_pParam); m_hr=m_pRecordSet.CreateInstance(__uuidof(Recordset)); if(FAILED(m_hr)) { m_pConnection->Close(); m_pConnection.Release(); ::CoUninitialize(); //Log error return NULL; } //Execute the SP m_pRecordSet->CursorType=adOpenStatic; m_pRecordSet=m_pCommand->Execute(NULL,NULL,adCmdStoredProc); return m_pRecordSet; }//try block catch(_com_error &comExcep) { //Handle the error } catch(CException * GenExcep) { //Handle the error Ge

    N 1 Reply Last reply
    0
    • A anju

      Hi,All RecordCount Property giving me -1 value Please read my code and give me where i am doing wrong; and also please comment on my Code(if their any mistakes) Thanks in Advance.. /////////////This is my code To Test the Function//////////////////// _RecordsetPtr pRst; CString strTemp; pRst.CreateInstance(__uuidof(Recordset)); pRst=GetData(1); if(pRst!=NULL) { int nCount=(int)pRst->RecordCount; strTemp.Format("%d",nCount); AfxMessageBox(strTemp); } else { AfxMessageBox("Recordset null"); } pRst.Close(); pRst.Release(); //////////////////////////////////// ///////////////////This is my funtion which will return me Recordset object/////////// _RecordsetPtr GetData(int nType) { CString strType; strType.Format("%d",nType); try { //COM Library Initialization if(FAILED(::CoInitialize(NULL))) { //Log error return NULL; }//if(FAILED(::CoInitialize(NULL)) //Open the Connection m_hr=m_pConnection.CreateInstance(__uuidof(Connection)); if(FAILED(m_hr)) { ::CoUninitialize(); //Log error return NULL; } m_strCnnString=GetConnectionString();//It will give me the Connection String _bstr_t cnnString(m_strCnnString); _bstr_t bstrEmpty(""); m_hr=m_pConnection->Open(cnnString,bstrEmpty,bstrEmpty,adConnectUnspecified); if(FAILED(m_hr)) { m_pConnection.Release(); ::CoUninitialize(); //Log error return NULL; } //Get the Command objet m_hr=m_pCommand.CreateInstance(__uuidof(Command)); if(FAILED(m_hr)) { m_pConnection->Close(); m_pConnection.Release(); ::CoUninitialize(); //Log error return NULL; } m_pCommand->ActiveConnection=m_pConnection; m_pCommand->CommandText="Sp_GetData"; m_pCommand->CommandType=adCmdStoredProc; //Append the Parameters to Command object //Type Parameter m_pParam=m_pCommand->CreateParameter(_bstr_t("Type"),adInteger,adParamInput,4,_variant_t(strType)); m_pCommand->Parameters->Append(m_pParam); m_hr=m_pRecordSet.CreateInstance(__uuidof(Recordset)); if(FAILED(m_hr)) { m_pConnection->Close(); m_pConnection.Release(); ::CoUninitialize(); //Log error return NULL; } //Execute the SP m_pRecordSet->CursorType=adOpenStatic; m_pRecordSet=m_pCommand->Execute(NULL,NULL,adCmdStoredProc); return m_pRecordSet; }//try block catch(_com_error &comExcep) { //Handle the error } catch(CException * GenExcep) { //Handle the error Ge

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      anju wrote: RecordCount Property giving me -1 value MSDN has an article: PRB: ADO: Recordcount May Return -1[^] You might also review the example on this site: Filter and RecordCount Properties Example (VC++)[^]. Here is a snip of what I am talking about.

      rstPublishers->CursorType = adOpenStatic;

          TESTHR(   rstPublishers->Open("publishers",strCnn, 
               adOpenStatic , adLockReadOnly,adCmdTable));
      
          // Populate the Recordset.
          intPublisherCount = rstPublishers->RecordCount;
      

      Hope this helps. :) Nick Parker
      May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing


      A 1 Reply Last reply
      0
      • N Nick Parker

        anju wrote: RecordCount Property giving me -1 value MSDN has an article: PRB: ADO: Recordcount May Return -1[^] You might also review the example on this site: Filter and RecordCount Properties Example (VC++)[^]. Here is a snip of what I am talking about.

        rstPublishers->CursorType = adOpenStatic;

            TESTHR(   rstPublishers->Open("publishers",strCnn, 
                 adOpenStatic , adLockReadOnly,adCmdTable));
        
            // Populate the Recordset.
            intPublisherCount = rstPublishers->RecordCount;
        

        Hope this helps. :) Nick Parker
        May your glass be ever full. May the roof over your head be always strong. And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing


        A Offline
        A Offline
        anju
        wrote on last edited by
        #3

        Hi Nick, Thanks for your reply, Still now RecordCount Property giving me -1; what your provided information is good if i am getting the recordset through "adCmdText or adCmdTable" but here i am getting the recordset through "adSotredProc". r u observed this difference? i am getting full recordset with out any problem except RecordCount. Actually my problem was concentrated here.... //Execute the SP m_pRecordSet->CursorType=adOpenStatic; m_pRecordSet=m_pCommand->Execute(NULL,NULL,adCmdStoredProc); return m_pRecordSet; ---In the above code.Eventhogh i assigned "adOpenStatic" to CursorType it is not replicating it is defaultly taking the "adOpenForwardOnly". ////////// _RecordsetPtr pRst; CString strTemp; pRst.CreateInstance(__uuidof(Recordset)); pRst=GetData(1); if(pRst!=NULL) { int nCount=(int)pRst->RecordCount; strTemp.Format("%d",nCount); AfxMessageBox(strTemp); } else { AfxMessageBox("Recordset null"); } pRst.Close(); pRst.Release(); ///////////////////////// ----Can u tell where i have to set the CursorType? Once again i am waiting for your reply... thanks in advance:rose::rose::rose: anju

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups