Link to home
Start Free TrialLog in
Avatar of Paullkha
PaullkhaFlag for United States of America

asked on

ADO OLE MFC

I have been using MFC CRecordset CDatabase for some time. With VB I use ADO.
Well, I am starting a small new project and want to use different database access methods under VC++, such as ADO. But after looking through this site, does not look like many people use this.

?If I want to enhance my skill set, should I look into ADO or OLE under VC++ 6.0.
?If so, which one, and links to some tutorials.
?What about OLE DB consumer templates, what the hell is this?
?Are there wizards in VC++ 6.0 that help with integerating ADO such as with CRecordset class or is it all straight coding.

Back-end db is SQL server 7.0




Avatar of DanRollins
DanRollins
Flag of United States of America image

>>?If I want to enhance my skill set, should I look into ADO or OLE under VC++ 6.0.
Probably OLEDB since it is the coming wave.  But you will find more examples in MDSN and elsewhere for ADO.  Both are infinitely harder to use than CRecordset objects.

>>?Are there wizards in VC++ 6.0 that help with
>> integerating ADO such as with CRecordset class or is it
>> all straight coding.
All straight coding, and not much of it is easy.  If you use CRecordset, the tne ClassWizard makes named variables for each field of each table.  Change the table and the ClassWizard can update your object with a few clicks.

If you use ADO or OLEDB, you will be digging around all through your code to locate the changed spelling of the table/field name.  And the error won't occur unti runtime (then the data provider says "I've never heard of that field" and rejects the whole query.)

-- Dan
Incidently, here is the best code sample for ADO access that I've ever seen.  It is PERFECT because it does the bare minimum:

#include <stdio.h>
#include <afxdisp.h>
#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace

#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
                                  if (FAILED(_hr)) _com_issue_error(_hr); }

#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
#define UC (char *)
struct InitOle {
    InitOle()  { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;       // Global Instance to force load/unload of OLE

void main(){
    _RecordsetPtr   spRS;
    _ConnectionPtr  spCON;
    try{
        CREATEiNSTANCE(spCON,Connection);
        spCON->ConnectionString = L"driver={sql server};SERVER=(local);Database=pubs;UID=sa; PWD=;";
        // spCON->ConnectionString =L"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=authors.MDB;DefaultDir=C:\\test;";
             
        spCON->Open( "", "", "", -1 );
        CREATEiNSTANCE(spRS,Recordset)
        spRS->PutRefActiveConnection( spCON );
        spRS->Open("select au_lname, au_fname from authors",
               vtMissing, adOpenKeyset,
            adLockBatchOptimistic, -1
          );
        while(spRS->adoEOF == false){
            printf("au_lname = %s  au_fname = %s \n",
                    UC _bstr_t(RsITEM(spRS,0L)),
                    UC _bstr_t(RsITEM(spRS,"au_fname"))
               );
            spRS->MoveNext();
        }
        spRS->Close();
        spCON->Close();
    }
    catch( _com_error &e){
        _bstr_t bstrSource(e.Source());
        _bstr_t bs =  _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
            + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
            + _bstr_t(e.Description());
       
        MessageBox(0,bs,bstrSource, MB_OK);
    }          
}

-- Dan
Avatar of Paullkha

ASKER


Looks like no-one else disagrees.

When should one use ADO over the CRecordset object, since my reservations about ADO seem validated? I have seen it used in some examples on the web, but are there any compelling reasons to use it?
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Moondancer
Moondancer

This question is current, others are not and need your attention.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still inactive in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20292692.html
https://www.experts-exchange.com/questions/Q.20255048.html
https://www.experts-exchange.com/questions/Q.20284498.html
https://www.experts-exchange.com/questions/Q.20284957.html
https://www.experts-exchange.com/questions/Q.20293564.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20089266.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
Thank you for returning and finalizing this.
Moondancer - EE Moderator