Hi Guys,
Not sure where I'm going wrong but here's my code:
[CODE/] //Create a database (TO DO, close the database)
QString strServerName = "LOCALHOSE\\SQLITE";
QString strDBName = "test.db";
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); //EDIT in final to incorporate multiple connections, will need a tracking variable that will track how many connections are opened and create a new unique one.
/*
db.setConnectOptions();
QString dsn = QString("DRIVER={SQL Native Client}; SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").ar g(strServerName).arg(strDBName);
db.setDatabaseName(dsn);
*/
db.setDatabaseName(strDBName);
bool dbOpen = db.open("test.db", NULL);
if(dbOpen == TRUE)
{
qDebug() << "Database open";
QSqlQuery query;
query.exec("SELECT Row FROM tblField WHERE Page = one");
qDebug() << query.lastError().text(); //if error executing SQL statement occurs, get error
}
if(dbOpen == FALSE)
{
qDebug() << "Last error " << db.lastError().text();
}
//Button cNav;
db.close();
db.removeDatabase("test.db");[\CODE]
Basically I get the output of:
Database open
"no such table: tblField Unable to execute statement"
Not sure why, I've got the database in the folder where the .exe is, in fact I've got in about 10 different folders just to be sure. I know that if it can't find a database, it'll create a new blank one, which I think is what is happening, question is, why?
Bookmarks