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

QUERY NOT WORKING

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 944 Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by SGaist
    #2

    Hi,

    There might be some space missing in your query string.

    You should also surround your query.exec call with an if or you will always print something.

    You should also print the output of lastQuery.

    On a side note, please don't write title in all caps. In written language it's considered shouting and rude.

    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
    • GREYONG Offline
      GREYONG Offline
      GREYON
      wrote on last edited by
      #3

      Okay for responding.but I don't understand when you say the maybe some space missing in the query.And where exactly can an If be there?

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

        The way you built your query string, "VALUES" is likely directly after the ")".

        If (!query.exec()) {
            // put here the code that should run in case of failure
        }
        

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

        GREYONG 1 Reply Last reply
        0
        • SGaistS SGaist

          The way you built your query string, "VALUES" is likely directly after the ")".

          If (!query.exec()) {
              // put here the code that should run in case of failure
          }
          
          GREYONG Offline
          GREYONG Offline
          GREYON
          wrote on last edited by
          #5

          @SGaist okay I get your point,However,the code is there it's only that I didn't include it when sending .it comes just after the **lastError ** line of code in my main code.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mchinand
            wrote on last edited by
            #6

            Check the output of QSqlQuery::boundValues() (after the binding calls), QSqlQuery::lastQuery() and/or QSqlQuery::executedQuery() to see if anything looks different from what you expect.

            GREYONG 1 Reply Last reply
            1
            • M mchinand

              Check the output of QSqlQuery::boundValues() (after the binding calls), QSqlQuery::lastQuery() and/or QSqlQuery::executedQuery() to see if anything looks different from what you expect.

              GREYONG Offline
              GREYONG Offline
              GREYON
              wrote on last edited by
              #7

              @mchinand Thanks let me try that way

              JonBJ 1 Reply Last reply
              0
              • GREYONG GREYON

                @mchinand Thanks let me try that way

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #8

                @GREYON
                @SGaist suggested you put a space into your )VALUES, did you at least try that?

                Otherwise: reduce your statement down till it works. Try it with only the SURNAME/:SURNAME column in it. Yes, the INSERT will error before inserting because of a lack of columns, but you are only interested in trying to get as far as that, if you do not get the Parameter count mismatch error you have succeeded. Then add the other columns back in.

                GREYONG 1 Reply Last reply
                0
                • JonBJ JonB

                  @GREYON
                  @SGaist suggested you put a space into your )VALUES, did you at least try that?

                  Otherwise: reduce your statement down till it works. Try it with only the SURNAME/:SURNAME column in it. Yes, the INSERT will error before inserting because of a lack of columns, but you are only interested in trying to get as far as that, if you do not get the Parameter count mismatch error you have succeeded. Then add the other columns back in.

                  GREYONG Offline
                  GREYONG Offline
                  GREYON
                  wrote on last edited by
                  #9

                  @JonB Thanks, your idea of going through it one by one has worked thanks for your help

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    So what was the actual error in your code above then?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    GREYONG 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      So what was the actual error in your code above then?

                      GREYONG Offline
                      GREYONG Offline
                      GREYON
                      wrote on last edited by
                      #11

                      @Christian-Ehrlicher it's like one of the column name was not correctly spelled though I couldn't pin point it exactly cause I was just going through them one by one until all of them worked.

                      1 Reply Last reply
                      0

                      • Login

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