Results 1 to 2 of 2

Thread: Connecting to MS ACCESS

  1. #1
    Join Date
    Jul 2007
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Connecting to MS ACCESS

    Hi , i am trying to connect to an access database (.mdb) using the ODBC driver.
    I get the table names but i have trouble making a query
    Here is some code

    QSqlDatabase mgDb = QSqlDatabase::addDatabase("QODBC","rastrac");
    QSqlQuery query(mgDb);

    // Open connection.
    mgDb.setHostName("localhost");
    mgDb.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=rastrac.mdb");

    if(!mgDb.open())
    {
    login->setDbHost( QString("ODBC3:pen() : error opening connection : ") +
    mgDb.lastError().text() + "\n");
    }
    else
    login->setDbHost( QString("Success ") );

    QStringList list = mgDb.tables(QSql::AllTables);
    for(int i=0;i<list.size(); ++i)
    {
    login->setDbUser(QString("Table names ") + list.at(i)) ;
    }

    //This is giving me problems
    if(!query.exec("SELECT Day FROM VehicleState;"))
    ...... // error

    thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connecting to MS ACCESS

    Do you get any errors? What does query.lastError() return?

Similar Threads

  1. ODBC and MS Access
    By allensr in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2007, 00:41
  2. connecting QT3 with MS Access database
    By raghvendramisra in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2007, 10:48
  3. Database access from Qt
    By nimmyj in forum Newbie
    Replies: 1
    Last Post: 23rd November 2006, 10:52
  4. Replies: 1
    Last Post: 4th October 2006, 17:05
  5. Replies: 5
    Last Post: 14th July 2006, 23:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.