SQLite and QSqlQuery "Parameter count mismatch" Error
-
What Qt version do you use?
Please check the return values of query.prepare() and bindValue(). Also re-write your query toUPATE summary_payment SET product_name = :product_name, price = :price WHERE id = :id
-
@ppitu
What did you do about @Christian-Ehrlicher'sPlease check the return values of query.prepare() and bindValue().
?
We do not know what is in your database. We don't know whether you have a table named
summary_payment
. We don't know whether it has the column names you specify. We don't know whether your code is supplying good values for these. -
This works fine for me:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.open(); QSqlQuery query(db); query.exec("CREATE TABLE summary_payment (product_name text, price real, id primary key)"); query.prepare("UPDATE summary_payment SET product_name = :product_name, price = :price WHERE id = :id"); query.bindValue(":product_name", QLatin1String("product_name")); query.bindValue(":price", 8); query.bindValue(":id", 7); if (!query.exec()) { qDebug() << query.lastError().databaseText() << query.lastError().driverText(); }
-
Here is a link to the whole file.
I create the table the same as @Christian-Ehrlicher , and insert to database work correct i have a problem with update and remove -
Did you try my code? If so adjust yours until it's working as expected.
-
@Christian-Ehrlicher i tried your code (in new project) and it worked fine.
But when i change code in my app I get this error: "" "Parameter count mismatch" -
Then simplify your code until it works or looks like mine to find your problem.
-