Unsolved updateQuery.exec("UPDATE wezwanie SET kontrolna = 0,pierwsza = 0, problemj = 0 WHERE id=Variavle");
-
Hello,
How i Can use variable to indicate id number.My code is:
Void MainWindow::on_tzdz_clicked() { QSqlQuery updateQuery = QSqlQuery(db); query.first(); while(query.next()) { updateQuery.exec("UPDATE wezwanie SET kontrolna = 0,pierwsza = 0, problemj = 0 WHERE id=8"); ui->statusBar->showMessage(QString("Koniec Kontroli"+ updateQuery.lastError().text())); } }```
-
Hello,
The query you are passing toupdateQuery.exec()
is a string you can useQString
and change it like thisVoid MainWindow::on_tzdz_clicked() { QSqlQuery updateQuery = QSqlQuery(db); query.first(); while(query.next()) { updateQuery.exec(QString("UPDATE wezwanie SET kontrolna = 0,pierwsza = 0, problemj = 0 WHERE id=") + QString::number(8)); ui->statusBar->showMessage(QString("Koniec Kontroli"+ updateQuery.lastError().text())); } }
Use a variable instead of 8.
-
Hi,
The cleanest way would be to use a prepared query. See QSqlQuery::prepare.