[SOLVED] SQLite Error: No such table!
-
wrote on 2 Dec 2014, 08:36 last edited by
Hello,
I made a new sqlite database named auto.db with one table named autos(varchar(50),varchar(50),varchar(50),real,integer)
I have also insert one dataset.If i use cmd.exe i can execute the sql statement which is in my code.
In QT there is no such table autos???this is my code in the constructor:
@
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:/sqlite/auto.db");
db.open();if(!db.open()) ui->label_25->setText("FAILED TO OPEN THE DB"); else ui->label_25->setText("CONNECTED DB"); QSqlQuery query1; query1.exec("SELECT name FROM autos WHERE kraftstoff = 'Diesel'"); qDebug() << query1.size(); qDebug() << query1.isSelect(); qDebug() << query1.isValid(); qDebug() << query1.lastError(); while(query1.next()) { QString name = query1.value(0).toString(); qDebug() << name; }
@
and thats my console:
-1
false
false
QSqlError("1", "Unable to execute statement", "no such table: autos") -
Hi,
-
No need to open database twice. Instead you can do this
@
bool isOpened = db.open();
if(isOpened) {
qDebug() << "opened;
} else {
qDebug() << "Error";
}
@ -
Try printing the error in else part to get the exact error.
-
Try passing the current database to QSqlQuery as
@
QSqlDatabase db = QSqlDatabase::database;
QSqlQuery query1(db);
query1.exec("SELECT name FROM autos WHERE kraftstoff = 'Diesel'");
@
-
-
wrote on 2 Dec 2014, 14:31 last edited by
Do I have to install any drivers for sqlite additional to QT Creator?
-
wrote on 2 Dec 2014, 19:12 last edited by
Here is my solution:
It was the database path. i used auto instead of auto.db
@
QString dbName="C:/sqlite/auto";
@
1/4