PDA

View Full Version : Connecting to MS ACCESS



berzeck
21st November 2007, 21:49
Hi , i am trying to connect to an access database (.mdb) using the ODBC driver.
I get the table names but i have trouble making a query
Here is some code

QSqlDatabase mgDb = QSqlDatabase::addDatabase("QODBC","rastrac");
QSqlQuery query(mgDb);

// Open connection.
mgDb.setHostName("localhost");
mgDb.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=rastrac.mdb");

if(!mgDb.open())
{
login->setDbHost( QString("ODBC3::open() : error opening connection : ") +
mgDb.lastError().text() + "\n");
}
else
login->setDbHost( QString("Success ") );

QStringList list = mgDb.tables(QSql::AllTables);
for(int i=0;i<list.size(); ++i)
{
login->setDbUser(QString("Table names ") + list.at(i)) ;
}

//This is giving me problems
if(!query.exec("SELECT Day FROM VehicleState;"))
...... // error

thank you

jacek
21st November 2007, 22:30
Do you get any errors? What does query.lastError() return?