Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to create a new xx.mdb(MS access file) file using qt?

    General and Desktop
    sql access
    3
    4
    2259
    Loading More Posts
    • 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.
    • Mactarvish
      Mactarvish last edited by

      When I use sqlite, if I wanna create a new xx.db file, I usually use this function:

      ...
      QSqlDatabase::setDatabaseName("test.db");
      ...

      If the test.db is NOT exist, qt will create it automatically. But when I turn to MS access and still use this function:

      ...
      QSqlDatabase accessdb = QSqlDatabase::addDatabase("QODBC", "test");
      QString dsn = QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=mytest.mdb");
      accessdb.setDatabaseName(dsn);
      if (!accessdb.open())
      {
      qDebug() << accessdb.lastError().text();
      }
      ...

      I can only be told “[Microsoft][ODBC Microsoft Access driver] file not found '(unknown)'"
      which might means qt only find it without creating it automatically.

      How to create a new xx.mdb file using qt?

      1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        It looks like your Qt installation does not contain the driver for MS Access

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

        Mactarvish 1 Reply Last reply Reply Quote 0
        • Mactarvish
          Mactarvish @jsulm last edited by

          @jsulm But I'm sure I installed it formly...

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi and welcome to devnet,

            I haven't used ODBC actively but IIRC, you have to do some setup in order to access MSAccess databases through it (not unlike what you would have to do for a MySQL database) so basically you have to provide the .mdb file.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post