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
Forum Updated to NodeBB v4.3 + New Features

How to insert data in Microsoft Access file

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.7k 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 8 May 2017, 13:03 last edited by rockon209 5 Aug 2017, 13:16
    #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
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 8 May 2017, 13:16 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 8 May 2017, 13:19 last edited by rockon209 5 Aug 2017, 13:19
        #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!
        }
        ...

        J 1 Reply Last reply 9 May 2017, 04:46
        1
        • R rockon209
          8 May 2017, 13:19

          @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!
          }
          ...

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 9 May 2017, 04:46 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 9 May 2017, 06:49 last edited by
            #5

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

            J 1 Reply Last reply 9 May 2017, 06:58
            0
            • R rockon209
              9 May 2017, 06:49

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 9 May 2017, 06:58 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 9 May 2017, 07:35 last edited by rockon209 5 Sept 2017, 07:35
                #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")

                J 1 Reply Last reply 9 May 2017, 07:47
                0
                • R rockon209
                  9 May 2017, 07:35

                  @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")

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 9 May 2017, 07:47 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 9 May 2017, 07:52 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

                    1/9

                    8 May 2017, 13:03

                    • Login

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