ADO Wrapper Classes

Environment: VC6 SP4, NT4 SP6

Acknowledgements

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.

Downloads

Download source - 2 Kb
Download demo project - 121 Kb


Comments

  • 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.

    Reply
  • 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()
    {
    m_pRecordset->MoveNext;
    }


    //Code:

    //In the Command Button

    for(int i=0;i<5;i++)
    {
    ret=(char*)_bstr_t(theApp.m_dyndb.GetFieldVal(0,"Company_Name"));
    m_List.AddString(ret);
    theApp.m_dyndb.MoveNext();
    }
    ////////////////////////////////////////////////////////
    The Warning During Compiling is:
    --------------------Configuration: AdoTest - Win32 Debug--------------------
    Compiling...
    Dyndb.cpp
    \\Blackpanther\Source_Code\VC\AdoWrapper\Dyndb.cpp(215) : warning C4551: function call missing argument list
    Linking...

    AdoTest.exe - 0 error(s), 1 warning(s)
    ///////////////////////////////////////////////////////////
    What is the Argument List?
    ///////////////////////////////////////////////////////////
    I tried adding
    //.ccp File
    void CDyndb::MoveNext()
    {
    m_pRecordset->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()
    {
    //m_pRecordset->MoveNext();
    CDynRec temprec;
    temprec.m_pRecordset->MoveNext();
    }
    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);
    AfxMessageBox(a);
    ////////////////////////////////////////////////////
    After further research the RecordCount is always 4,199,165
    This seems strange
    ////////////////////////////////////////////////////

    Thanks for your previous help.
    Doug


    Reply
  • 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:

    "short(variantdata);"
    vardat=theApp.m_dyndb.GetFieldVal(0,2);

    So Here was one attempt that cause a crash:

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

    or
    short vardat;
    vardat= theApp.m_dyndb.GetFieldVal(0,"Companies");
    //a.Format("FV=%s",vardat);
    AfxMessageBox(vardat); I also tried (a) in the Afx

    or

    short(variantdata) vardat;
    vardat= theApp.m_dyndb.GetFieldVal(0,2);
    //a.Format("FV=%s",vardat);
    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,
    Doug

    Reply
  • 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?

    Reply
  • All Fixed...

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

    Originally posted by: Dogu Tumerdem

    download new version from :

    http://freedrive.com
    user : dogutumerdem
    pass : humankind

    dyndb.zip

    Reply
  • 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.
    Registers:
    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...

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

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • This ESG study by Mark Peters evaluated a common industry-standard disk VTl deduplication system (with 15:1 reduction ratio) versus a tape library with LTO-5, drives with full nightly backups, over a five-year period.  The scenarios included replicated systems and offsite tape vaults.  In all circumstances, the TCO for VTL with deduplication ranged from about 2 to 4 times more expensive than the LTO-5 tape library TCO. The paper shares recent ESG research and lots more. 

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds