QSql参数计数不匹配

时间:2016-10-13 13:58:06

标签: c++ qt sqlite

我正在使用QtSql和sqlite,问题是:

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();

我得到“参数计数不匹配”

1 个答案:

答案 0 :(得分:0)

@tskoglund在Qt论坛中的解决方案&lt; https://forum.qt.io/topic/72260/qsqlquery-select-statment/5&gt;

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

QSqlQuery查询;