问题
I wanted to use read and write mdb
file (Ms Access file) and I am completely new in using ODBC
in Qt.
So can anyone help me to know whether should i need to download the drivers and if yes then from where can i download ? and if you know about connectivity then any help would be appriciated.
回答1:
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();
回答2:
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.
来源:https://stackoverflow.com/questions/4051147/odbc-driver-use-in-qt