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. QSql Update
Qt 6.11 is out! See what's new in the release blog

QSql Update

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.8k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have the following code to update the db:

    model->setData (index,edit->text ());
                QVariant f(index.data(Qt::DisplayRole));
                QString modified;
                modified = f.toString ();
                qDebug() << "Modified: " << modified;
    
                QModelIndex updateIndex(index.model ()->index(index.row (),0,index.parent ()));
    
                QString fixID;
                QVariant v(updateIndex.data (Qt::DisplayRole));
                fixID = v.toString ();
                qDebug() << "FixID: " << fixID;
    
                QSqlQuery fixquery;
    
                fixquery.prepare("UPDATE Items SET (Name) VALUES :Name WHERE ID = :fixID");
                fixquery.bindValue (":Name", modified);
    

    I ran debug and all the values are correct (in fixID and modified) but there are no changes in the db. What did I miss? Thank you.

    1 Reply Last reply
    0
    • Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by
      #2

      hi,

      did u call fixquery.exec();

      Pradeep Kumar
      Qt,QML Developer

      G 1 Reply Last reply
      1
      • Pradeep KumarP Pradeep Kumar

        hi,

        did u call fixquery.exec();

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @Pradeep-Kumar
        Hi,
        Now I did:

            fixquery.prepare("UPDATE Items SET (Name) VALUES :Name WHERE ID = :fixID");
                    fixquery.bindValue (":Name", modified);
        
                    fixquery.exec ();
        

        but same results.

        1 Reply Last reply
        0
        • Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by Pradeep Kumar
          #4

          Syntax for update query:

          UPDATE tablename SET columnname = 'value' WHERE columnname = 'value';

          can u try

                  QSqlQuery fixquery;
                  fixquery.prepare("UPDATE Items SET Name =  :Name WHERE ID = :fixID");
                  fixquery.bindValue (":Name", modified);
                  fixquery.bindValue (":fixID", fixID );
                  fixquery.exec ();
          

          Hope this helps you,

          Thanks,

          Pradeep Kumar
          Qt,QML Developer

          G 1 Reply Last reply
          6
          • Pradeep KumarP Pradeep Kumar

            Syntax for update query:

            UPDATE tablename SET columnname = 'value' WHERE columnname = 'value';

            can u try

                    QSqlQuery fixquery;
                    fixquery.prepare("UPDATE Items SET Name =  :Name WHERE ID = :fixID");
                    fixquery.bindValue (":Name", modified);
                    fixquery.bindValue (":fixID", fixID );
                    fixquery.exec ();
            

            Hope this helps you,

            Thanks,

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            @Pradeep-Kumar
            Thank you. It worked.

            1 Reply Last reply
            1
            • Pradeep KumarP Offline
              Pradeep KumarP Offline
              Pradeep Kumar
              wrote on last edited by
              #6

              Hi
              @gabor53

              Good to hear,it helped you.

              Cheers,
              Thanks,

              Pradeep Kumar
              Qt,QML Developer

              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