ODBC driver use in Qt

不想你离开。 提交于 2019-12-07 05:30:01

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!