?
Solved

Creating an ADO recordset in C++

Posted on 2000-02-08
1
Medium Priority
?
854 Views
Last Modified: 2008-03-17
I need sample code to show me how to build my own ADO recordset in VC++.  So, I need to create a blank recordset, append field names, open the blank recordset without having a live connection, add new values to the fields I created, and then update the recordset.
0
Comment
Question by:Fantino
1 Comment
 

Accepted Solution

by:
juansanchez earned 200 total points
ID: 2513455
#import "c:\archivos de programa\archivos comunes\system\ado\msado15.dll" no_namespace implementation_only rename("EOF", "EndOfFile")      


        _RecordsetPtr pRs;
        _variant_t vNull;
        vNull.vt=VT_ERROR;
        vNull.scode=DISP_E_PARAMNOTFOUND;
      try{
            pRs.CreateInstance(__uuidof( Recordset));
   
            pRs->CursorLocation  =  adUseClient;
          pRs->CursorType      = adOpenStatic;
          pRs->Fields->Append(_T("field1"), adBSTR, sizeof(BSTR), adFldUnspecified);
            pRs->Fields->Append(_T("fieldint2"), adInteger, sizeof(int), adFldUnspecified);
          pRs->Fields->Append(_T("field3"), adBSTR, sizeof(BSTR), adFldUnspecified);

            pRs->Open(vNull, vNull, adOpenDynamic, adLockOptimistic, adCmdUnknown);

            pRs->AddNew();
      
          pRs->Update(_T("field1"), _variant_t((char*)"Value") );
            pRs->Update(_T("fieldint2"), _variant_t((long) 5) );
          pRs->Update(_T("field3"), _variant_t((char*)"Value") );  

            pRs->AddNew();
      
          pRs->Update(_T("field1"), _variant_t((char*)"Value2") );
            pRs->Update(_T("fieldint2"), _variant_t((long) 3) );
          pRs->Update(_T("field3"), _variant_t((char*)"Value2") );            


                       
      
      }
      catch(_com_error &ce ){
           
             char szMsgEvent[256] ;
             sprintf(szMsgEvent,"CreaRecordSet: "
                                   "Description : %s "
                          "Message     : %s "
                          "HResult     : 0x%08x ",
                           (char*) ce.Description(),
                                   (char*) ce.ErrorMessage(), ce.Error());
        }


I hope this help you!!!!

thanks....

JISR
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question