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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds