Chiku
Chiku

Reputation: 111

ODBC driver use in Qt

I wanted to use read and write mdb file (Ms Access file).

Should I need to download the drivers? And if yes, from where?

Upvotes: 6

Views: 6755

Answers (2)

Haselnussstrauch
Haselnussstrauch

Reputation: 353

I had the same Problem.

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","AccessDB");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=C:/path/to/Database.mdb");
bool success = db.open();

works for me.

Upvotes: 2

Jérôme
Jérôme

Reputation: 27027

If you need to access an MS Access database with Qt, you don't need (if I'm not mistaken) to install anything regarding drivers (everything should be already there).

You can connect to a database with a connection string. Something like this :

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\path\\to\\mydatabase.mdb");
bool Success = db.open();

Upvotes: 6

Related Questions