How to insert data in Microsoft Access file
-
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
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!
}
... -
@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!
}
... -
@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
-
@jsulm
I am using the following codeQSqlDatabase 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") -
@jsulm
I am using the following codeQSqlDatabase 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")@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?