Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. updateQuery.exec("UPDATE wezwanie SET kontrolna = 0,pierwsza = 0, problemj = 0 WHERE id=Variavle");
Qt 6.11 is out! See what's new in the release blog

updateQuery.exec("UPDATE wezwanie SET kontrolna = 0,pierwsza = 0, problemj = 0 WHERE id=Variavle");

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Etro
    wrote on last edited by
    #1

    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()));
        } 
    }```
    1 Reply Last reply
    0
    • A Offline
      A Offline
      alirezafour
      wrote on last edited by
      #2

      Hello,
      The query you are passing to updateQuery.exec() is a string you can use QString and 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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved