Hi
You have a ":" too much for the bindvalue it seems.
Also just so we are on the same page. a ("INSERT INTO"..) sql statement do not return
rows. Only a("SELECT X ") sql would. (AFAIK)
bool createConnection() {
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"), "Click Cancel to exit.", QMessageBox::Cancel);
return false; }
QSqlQuery query;
qDebug() << "table:" << query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20), num int )");
query.exec("insert into person values(101, 'Dennis', 'Young','1')");
query.exec("insert into person values(102, 'Christine', 'Holand','2')");
query.exec("insert into person values(103, 'Lars junior', 'Gordon','4')");
query.exec("insert into person values(104, 'Roberto', 'Robitaille','5')");
query.exec("insert into person values(105, 'Maria', 'Papadopoulos','3')");
return true;
}
QSqlQuery query;
int ok = query.prepare("SELECT firstname,num FROM person WHERE num=:thenum AND firstname=:thename AND lastname=:lastname");
query.bindValue(":thenum", 4);
query.bindValue(":thename", "Lars junior");
query.bindValue(":lastname", "Gordon");
query.exec();