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. How to insert data in Microsoft Access file
Qt 6.11 is out! See what's new in the release blog

How to insert data in Microsoft Access file

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 3.2k Views
  • 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.
  • R Offline
    R Offline
    rockon209
    wrote on last edited by rockon209
    #1

    Hello Everyone,

    How I can insert two columns in Microsoft access file. Users will enter the value in Qtextfield (for example name and age) and i want to store it in access database
    Thanks in advance

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is no direct API available with Qt. Some third party C++ library may be available do this. You may check the same in Google.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rockon209
        wrote on last edited by rockon209
        #3

        @dheerendra
        I saw this in QT help but i dont know how to use it.
        http://doc.qt.io/qt-4.8/qsqldatabase.html#addDatabase

        ...
        db = QSqlDatabase::addDatabase("QODBC");
        db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
        if (db.open()) {
        // success!
        }
        ...

        jsulmJ 1 Reply Last reply
        1
        • R rockon209

          @dheerendra
          I saw this in QT help but i dont know how to use it.
          http://doc.qt.io/qt-4.8/qsqldatabase.html#addDatabase

          ...
          db = QSqlDatabase::addDatabase("QODBC");
          db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
          if (db.open()) {
          // success!
          }
          ...

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @rockon209 See here: http://stackoverflow.com/questions/22552302/how-to-use-m-s-access-in-qt

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • R Offline
            R Offline
            rockon209
            wrote on last edited by
            #5

            @jsulm
            I already saw this link but it doesnt work it still shows "Not ok"

            jsulmJ 1 Reply Last reply
            0
            • R rockon209

              @jsulm
              I already saw this link but it doesnt work it still shows "Not ok"

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @rockon209 Try to use absolute path to the database file. Currently you're using a relative path:

              DBQ=myaccessfile.mdb
              

              try

              DBQ=c:\\SOMEDIR\\myaccessfile.mdb
              

              Also, you always should check the errors - it helps to find out what is the problem! See http://doc.qt.io/qt-5/qsqldatabase.html#lastError

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • R Offline
                R Offline
                rockon209
                wrote on last edited by rockon209
                #7

                @jsulm
                I am using the following code

                QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                db.setDatabaseName("DRIVER={Microsoft Access Driver(*.accdb)};FIL={MS Access};DBQ=C:/.../.../..../Database1.accdb");

                if(db.open())
                  qDebug() << "oK";
                else
                  qDebug() <<  db.lastError();
                

                aand i got following the error
                QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified")

                jsulmJ 1 Reply Last reply
                0
                • R rockon209

                  @jsulm
                  I am using the following code

                  QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                  db.setDatabaseName("DRIVER={Microsoft Access Driver(*.accdb)};FIL={MS Access};DBQ=C:/.../.../..../Database1.accdb");

                  if(db.open())
                    qDebug() << "oK";
                  else
                    qDebug() <<  db.lastError();
                  

                  aand i got following the error
                  QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified")

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @rockon209 I'm not sure whether forward slashes are supported in this connection string, maybe you should try with back slashes:

                  db.setDatabaseName("DRIVER={Microsoft Access Driver(*.accdb)};FIL={MS Access};DBQ=C:\\...\\...\\....\\Database1.accdb");
                  

                  Also is the path correct?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rockon209
                    wrote on last edited by
                    #9

                    @jsulm

                    I also tried with backslash but getting the same error and the path is also correct.

                    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