ADO Wrapper Classes

Environment: VC6 SP4, NT4 SP6


This article is based in part on Bob Place's ADO is AOK (a simple ADO tutorial).

Wrapper Usage

This is consist of 2 classes.
  • CDyndb : This Class manages connections and recordsets. Recordsets are organized as linked list (CList) and you can access them using their ids.
  • CDynRec : This class is the node to populate for each recordsets.
Simply follow these steps in order to use the ADO wrapper classes:
  1. You need to add the following line stdafx.h :
  2. #import "c:\program files\common files\system\ado\msado21.tlb" no_namespace rename ("EOF", "adoEOF") 
  3. Call the OpenConn function
    theApp.m_dyndb.OpenConn("driver=sql server;server=dogu;UID=sa;PWD=;database=dbtraining;");
  4. Call OpenRec function
  5. theApp.m_dyndb.OpenRec("select * from Courses");
  6. Call GetFieldVal function to get the value of the fields. This function returns variant type. You can cast it as usual way like "short(variantdata);"
  7. vardat=theApp.m_dyndb.GetFieldVal(0,2);
  8. Call GetFieldType to get the type of the field. "en" has a definition like DataTypeEnum en; (see MSDN for details)
  9. en=theApp.m_dyndb.GetFieldType(0,2);
  10. Call GetFieldCount to get the number of the fields that selected in the recordset.

  11. Call GetFieldName to obtain the name of the field.
To iterate through a recordset, you can use the m_pRecordSet member functions MoveXXX.


Download source - 2 Kb
Download demo project - 121 Kb


  • This is not working.

    Posted by Haranadh on 02/28/2006 04:27am

    I tried to execute the demo project. but it is not executing. why? check once.

  • Recordset Navigator and Count

    Posted by Legacy on 02/22/2002 12:00am

    Originally posted by: Doug Hagerman

    I can now get the field values.

    However, I tried implementing a MoveNext Function to navigator the recordset, and although it didn't crash, it didn't seem to moveNext

    //.h File
    void MoveNext();

    //.ccp File
    void CDyndb::MoveNext()


    //In the Command Button

    for(int i=0;i<5;i++)
    The Warning During Compiling is:
    --------------------Configuration: AdoTest - Win32 Debug--------------------
    \\Blackpanther\Source_Code\VC\AdoWrapper\Dyndb.cpp(215) : warning C4551: function call missing argument list

    AdoTest.exe - 0 error(s), 1 warning(s)
    What is the Argument List?
    I tried adding
    //.ccp File
    void CDyndb::MoveNext()
    the () to the end of move next and although it eliminates the compile warning it crashed with Abnormal Program Termination
    So Next I tried
    void CDyndb::MoveNext()
    CDynRec temprec;
    and it still gives
    Abnormal Program Termination
    and crashes

    Also, the record count give me over 4 million records when there is just over 1000?

    CString a;
    a.Format("Record Count=%d",theApp.m_dyndb.GetRecCount);
    After further research the RecordCount is always 4,199,165
    This seems strange

    Thanks for your previous help.

  • IT Manager

    Posted by Legacy on 02/21/2002 12:00am

    Originally posted by: Doug Hagerman

    I have used this example in for ADO wrapper in C and the GetFieldCount, GetFieldType work but I also get a Run Time Error that says abnormal program termination.

    How do I get a Company_Name for instance into a string variable so I can use the data from the Recordset?

    In the # 4 Example I don't understand how to define the following:


    So Here was one attempt that cause a crash:

    short(variantdata) vardat;
    vardat= theApp.m_dyndb.GetFieldVal(0,"Companies");
    AfxMessageBox(vardat); I also tried (a) in the Afx

    short vardat;
    vardat= theApp.m_dyndb.GetFieldVal(0,"Companies");
    AfxMessageBox(vardat); I also tried (a) in the Afx


    short(variantdata) vardat;
    vardat= theApp.m_dyndb.GetFieldVal(0,2);
    AfxMessageBox(vardat); I also tried (a) in the Afx

    So what am I doing wrong?

    Also, how do you count the # of records in a Record Set?

    Please Help,

  • Problem

    Posted by Legacy on 04/12/2001 12:00am

    Originally posted by: zhouhao

    I think the #import will cause problem some times because the .dll or tlb file will be installed somewhere instead of c:\program\common files\... so that you need to recompile your program before you distribute it. Is there any other way to overcome this problem?

  • All Fixed...

    Posted by Legacy on 04/10/2001 12:00am

    Originally posted by: Dogu Tumerdem

    download new version from :
    user : dogutumerdem
    pass : humankind

  • Some Bugs !

    Posted by Legacy on 03/22/2001 12:00am

    Originally posted by: Anonymous

    After modifying button one to point to my database, table, and sa password, i got the About box's Button1 to display the message box(es) ok. But after i close the About box and then File->Exit the application I get ...

    ADOTEST caused an invalid page fault in
    module OLEDB32.DLL at 0167:1f9c7567.
    EAX=00000000 CS=0167 EIP=1f9c7567 EFLGS=00210246
    EBX=011b7188 SS=016f ESP=0065fa70 EBP=0065facc
    ECX=00000000 DS=016f ESI=00000000 FS=3dbf
    EDX=bffc9490 ES=016f EDI=00000000 GS=0000
    Bytes at CS:EIP:
    8b 77 08 8d 46 04 50 ff 15 08 11 9c 1f ff 46 1c
    Stack dump:
    00000000 00000000 1f9ce482 bff7438c 00000000 0065facc 011b7188 1f9ce46d 011b0728 1f9ca4b3 00000000 011b0728 00000000 011b0728 011b7188 011b4464

    I was ADO curious but not ADO employeed so I haven't spent any time debugging this.

    Just an FYI...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date