Ibrahim.Sluma Ibrahim.Sluma - 1 month ago 16
C++ Question

QSql Parameter count mismatch

I'm using QtSql with sqlite, the problem is:

QSqlQuery query;
query.prepare("SELECT * FROM [main].[items] WHERE barcode = ? OR name = ? ");
query.addBindValue(ui->Numberinput->text());
query.addBindValue(ui->search_item->text());
query.exec();
query.first();
qDebug() << query.lastError().text();


I'm getting "Parameter count mismatch"

Answer

solution by @hskoglund in Qt forum < https://forum.qt.io/topic/72260/qsqlquery-select-statment/5 >

QString s = QString("SELECT * FROM [main].[items] WHERE barcode = '%1' OR name = '%2'").arg(ui->Numberinput->text()).arg(ui->search_item->text());

QSqlQuery query(s);