Posted on 2002-04-25
Medium Priority
Last Modified: 2013-11-25
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

Question by:Paullkha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 49

Expert Comment

ID: 6970063
>>?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
LVL 49

Expert Comment

ID: 6970069
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;
        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 );
        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"))
    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

Author Comment

ID: 6978094

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?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 49

Accepted Solution

DanRollins earned 200 total points
ID: 6979211
ADO vs CRecordset:

With ADO and OLEDB, you use table/field names directly --  so your code looks about the same whether you are programming in VB, JavaScript, or C++ (of course C++ has all of that ugly COM overhead, as I've said).  And you can write very flexible SQL commands.  The data comes and goes as VARIENT data type which is very convenient for VB and JS, but awkward in C++.

With CRecordset, you let the framework transfer data between member variables and the database.  A VARCHAR data type comes in as an easy-to-use CString, etc.  The drawback is that there is a lot of 'inflexible' binding going on.  For instance, even if all you need is three columns, you will probably use a CRecordset that populates all member fields.  That means that there is a lot of data transfer going on that you don't need.

-- Dan

Expert Comment

ID: 6979377
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.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://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.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

*****  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
POINTS FOR EXPERTS awaiting comments are listed in the link below
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.
Moderator @ Experts Exchange

Expert Comment

ID: 6986285
Thank you for returning and finalizing this.
Moondancer - EE Moderator

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

719 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