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 to updateQuery.exec() is a string you can use QStringand change it like this

    Void 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.


  • Lifetime Qt Champion

    Hi,

    The cleanest way would be to use a prepared query. See QSqlQuery::prepare.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.