CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: [RESOLVED] Using ADO in VS2005

  1. #1
    Join Date
    Dec 2008

    [RESOLVED] Using ADO in VS2005

    This is my first time ever working with anything database related and I am having problems. I am trying to access a Microsoft Access Database that is stored locally on my machine, read some tables and extract the data. The code worked fine initially using DAO but I have been tasked to convert it so something not deprecated and I thought this ADO was the correct option.

    I have been using the following article as my reference since it is the only one I found that speaks in C++ terms.

    I have attached my ADO "wrapper" classes for reference. Pasted below is a code excerpt of me trying to open the database, access a table and extract some info. I am unable to connect to my database, what am I doing wrong? Any constructive advice is welcome, thank you.

    typedef struct
    int Index;
    CString Class;
    CString DerivedFrom;
    CString DeclassOn;
    CString DowngradeTo;
    CString DateOfSource;
    } TClass;


    void CClassification::ReadTable()
    TClass* ClassInfo;

    ADOTable ClassTable;

    // Open the database to access all the data to be written to the data files
    if (DatabaseFileName == "")
    DbName = GetDefaultDBName(); // Set database name for all tables
    DbName = DatabaseFileName;

    char CnnStr[200]="Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;"\
    "User ID=null;Initial Catalog=pubs;Data "\
    "Source=C:\Travis_Thread\tenpc\ten\Data\TEN Data Tables.mdb" ;

    TEN_Database.Open(NULL, NULL, CnnStr);

    TEN_Database.Execute("SELECT * FROM Classification", ClassTable);


    while (!ClassTable.IsEOF())
    ClassInfo = new TClass;

    ClassTable.Get( "[Classification Index]", m_Index);
    ClassTable.Get( "[Classification]", m_Classification.GetBuffer());
    ClassTable.Get( "[Derived From]", m_DerivedFrom.GetBuffer());
    ClassTable.Get( "[Declass On]", m_DeclassOn.GetBuffer());
    ClassTable.Get( "[Downgrade To]", m_DowngradeTo.GetBuffer());
    ClassTable.Get( "[Date Of Source]", m_DateOfSource.GetBuffer());

    ClassInfo->Index = m_Index;
    ClassInfo->Class = m_Classification;
    ClassInfo->DerivedFrom = m_DerivedFrom;
    ClassInfo->DeclassOn = m_DeclassOn;
    ClassInfo->DowngradeTo = m_DowngradeTo;
    ClassInfo->DateOfSource = m_DateOfSource;



    Attached Files Attached Files
    Last edited by Draznar; January 20th, 2009 at 11:57 PM. Reason: Added a missing Struct

Tags for this Thread

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

On-Demand Webinars (sponsored)