QSqlQuery select statment
-
i also tried
query.addBindValue(ui->Numberinput->text()); query.addBindValue(ui->search_item->text());
but the same
@MrLibya
this error is very unspecific and may also occur when the query itself is invalid.
As i already stated, whats about the table name[main].[items]
. Is this really correct?! -
@MrLibya
this error is very unspecific and may also occur when the query itself is invalid.
As i already stated, whats about the table name[main].[items]
. Is this really correct?!@raven-worx yep , i've already used this method in another function and it's work very well
void MainWindow::UpdateSearchItem(QStringList *List) { QSqlQuery query("SELECT * FROM [main].[items]"); while (query.next()) *List << query.value(1).toString(); }
-
Hi, maybe the text substitution goes haywire, to see the resolved text, try:
qDebug() << query.executedQuery();
@hskoglund said in QSqlQuery select statment:
qDebug() << query.executedQuery();
i got
"SELECT * FROM [main].[items] WHERE barcode = ? OR name = ? "
-
@hskoglund said in QSqlQuery select statment:
qDebug() << query.executedQuery();
i got
"SELECT * FROM [main].[items] WHERE barcode = ? OR name = ? "
-
Indeed the text substitution seems borked, you could try instead doing the text substitution directly yourself, something like this:
QSqlQuery query("SELECT * FROM [main].[items] WHERE barcode = '123' OR name = 'Smith'");
@hskoglund that will not really helps , goes the barcode - name , the user will input from line edit , so dose this only not work on sqlite ? if i use mysql it will work ??
-
Hi, you can build the select string something like this:
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);
@hskoglund thx it work :)