C++ and ADO (ActiveX Data Objects)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: C++ and ADO (ActiveX Data Objects)

  1. #1
    Join Date
    Nov 2008
    Posts
    6

    C++ and ADO (ActiveX Data Objects)

    Hello,

    I need to write a simple C++ program that:
    1) creates a table in an existing database
    2) inserts a record in the table and
    3) reads a record from the table

    Can someone provide me with a simple code (or suggest to me an online tutorial) for doing the above tasks using ADO (ActiveX Data Object)?

    I searched on the internet but I couldn't find a simple sample code addressing the above issues.

    My C++ program needs to access an SQL Server 2005 Database.

    Many thanks in advance.
    Last edited by nikolasapl; January 30th, 2011 at 01:32 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: C++ and ADO (ActiveX Data Objects)

    The Google search for ado vc++ example displays the first item to be ADO Code Examples in Visual C++. Now you can open any of the links to see how to begin working with ADO.
    To connect to the SQL Server 2005 Database - use one of the related connection strings.
    To create a table - use CREATE TABLE ... T_SQL clause, to insert a record - INSERT INTO ..., to read a record(s) - SELECT ... FROM ....
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: C++ and ADO (ActiveX Data Objects)

    Code:
    class CClientPlanRS : public CADORecordBinding, public CADORecordset
    {
    BEGIN_ADO_BINDING(CClientPlanRS)
        ADO_FIXED_LENGTH_ENTRY    (  1, 
           adInteger, m_lClient_Key, m_ulClient_KeyStatus, TRUE)
        ADO_VARIABLE_LENGTH_ENTRY2(  2, 
           adVarWChar, m_szClient_Name, sizeof(m_szClient_Name), 
           m_ulClient_NameStatus, TRUE)
        ADO_VARIABLE_LENGTH_ENTRY2(  3, 
           adVarWChar, m_szClient_Description, 
           sizeof(m_szClient_Description), 
           m_ulClient_DescriptionStatus, TRUE)
    END_ADO_BINDING()
    
    //Attributes
    
    public:
        LONG    m_lClient_Key;
        ULONG   m_ulClient_KeyStatus;
        CHAR    m_szClient_Name[51];
        ULONG   m_ulClient_NameStatus;
        CHAR    m_szClient_Description[256];
        ULONG   m_ulClient_DescriptionStatus;
        CClientPlanRS(CADODatabase* pDb, int nCacheSize = -1) :  
                CADORecordBinding(),                        
                CADORecordset(pDb, nCacheSize)              
                { SetRecordBinding(this); } 
    
    };
    however my recommendation would be to use ADO.NET under managed C++ or C# much easier
    you can use native SQL driver for .net or OLE.DB , ODBC

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: C++ and ADO (ActiveX Data Objects)

    Quote Originally Posted by aamir121a View Post
    Code:
    class CClientPlanRS : public CADORecordBinding, public CADORecordset
    {
    ...
    };
    Interesting!
    But how to create a Table using these classes?
    And what is CADORecordset class?
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2008
    Posts
    6

    Re: C++ and ADO (ActiveX Data Objects)

    Thanks for your replies, but I do not even know the very basics of ADO programming in C++, so they did not help me...

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: C++ and ADO (ActiveX Data Objects)

    Quote Originally Posted by nikolasapl View Post
    Thanks for your replies, but I do not even know the very basics of ADO programming in C++, so they did not help me...
    Well, I didn't know anything about ADO about 10 years ago either!
    But reading MSDN documentation + testing some of MSDN examples + searching in the Web about ADO helped me to understand it a little and then use it in my Apps.

    In addition to previous links:
    ADO is AOK (a simple ADO tutorial)
    ADO is AOK - Part II
    Victor Nijegorodov

  7. #7
    Join Date
    Nov 2008
    Posts
    6

    Re: C++ and ADO (ActiveX Data Objects)

    MSDN is really helpful

    Many thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center