Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]guys what's wrong with my code? microsoft access database
Forum Updated to NodeBB v4.3 + New Features

[solved]guys what's wrong with my code? microsoft access database

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lwiimbo
    wrote on last edited by
    #1

    Ok am trying to access a microsoft access database I've checked if the driver is available and yes QODBC is available I checked with the isDriverAvailable() code anyways here's my source code am looking forward to your advice:

    @
    QSqlDatabase DB = QSqlDatabase::addDatabase("QODBC");
    DB.setDatabaseName("Driver = {Microsoft Access Driver(.mdb,.accdb)}DSN='';DBQ=C:/Users/sweshi/Desktop/project.accdb");

    if(DB.open())
    {
    ui->label_6->setText("connected");
    }
    else
    {
    ui->label_6->setText("not connected");
    }
    @

    [andreyc EDIT]: added @ around code

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      small suggestion not sure if it will make a difference when using Qt but, I think the driver string is {Microsoft Access Driver (*.mdb, *.accdb)}.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lwiimbo
        wrote on last edited by
        #3

        Ok thanks for your contribution..still not working though..is there anything else I can add?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          What does "DB.lastError()":http://qt-project.org/doc/qt-5/qsqldatabase.html#lastError returns?

          1 Reply Last reply
          0
          • hskoglundH Online
            hskoglundH Online
            hskoglund
            wrote on last edited by
            #5

            Hi I opened an Access .mdb file in Qt before, like this:
            @
            QSqlDatabase DB = QSqlDatabase::addDatabase("QODBC");
            DB.setDatabaseName("Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:/Temp/Test.mdb;");@

            So maybe if you try to change your .setDatabaseName:
            @
            DB.setDatabaseName("Driver={Microsoft Access Driver (.mdb,.accdb)}; Dbq=C:/Users/sweshi/Desktop/project.accdb");
            @

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              There is also the issue of 32 bit and 64 bit access odbc drivers and on windows... you need to make sure you have the correct combination.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lwiimbo
                wrote on last edited by
                #7

                DB.lastError reports nothing thanks...@hskoglund I've tried that look at the application output: QSqlDatabase: QOBDC driver not loaded
                QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7. .@kenchan my windows 7 is 64bit but qt and ms access are both 32bit

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kenchan
                  wrote on last edited by
                  #8

                  I have a feeling it might be a problem with your ODBC driver settings on windows but can't be sure though

                  Are you aware of the issue discussed here http://support.microsoft.com/kb/942976

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lwiimbo
                    wrote on last edited by
                    #9

                    Thanks bro its working thanks to that link

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kenchan
                      wrote on last edited by
                      #10

                      Glad I could be of help. It was not a Qt thing after all :-)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved