how to connect to sqlite database
-
wrote on 14 May 2016, 08:15 last edited by
i want to connect to sqlite database
this is my code:QSqlDatabase Database; Database.addDatabase("QSQLITE"); Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db"); if (!Database.open()) { qDebug() << Database.lastError().text(); }
but return me "Driver not loaded Driver not loaded"
I copy qsqlite.dll in sqldrivers folder inside my app folder but don't work
-
i want to connect to sqlite database
this is my code:QSqlDatabase Database; Database.addDatabase("QSQLITE"); Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db"); if (!Database.open()) { qDebug() << Database.lastError().text(); }
but return me "Driver not loaded Driver not loaded"
I copy qsqlite.dll in sqldrivers folder inside my app folder but don't work
-
wrote on 14 May 2016, 16:52 last edited byThis post is deleted!
-
wrote on 14 May 2016, 16:53 last edited by
You need to assign the connection like this:
QSqlDatabase Database; Database = QSqlDatabase::addDatabase("QSQLITE"); Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db"); if (!Database.open()) { qDebug() << Database.lastError().text(); }
-
wrote on 31 May 2016, 16:16 last edited by
about how to connect to sqlite database, what's the best form to do the connection?, once tiem at start and only get connexion or connect and close on each query.
and is possible do update with bindvalue?thank you, sorry for my english!
-
about how to connect to sqlite database, what's the best form to do the connection?, once tiem at start and only get connexion or connect and close on each query.
and is possible do update with bindvalue?thank you, sorry for my english!
@Yugui
Often best design is open once at start.
and close at end.- and is possible do update with bindvalue?
yes. it is.
QSqlQuery query; query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)"); query.bindValue(":id", 1001); query.bindValue(":forename", "Bart"); query.bindValue(":surname", "Simpson"); query.exec();