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. QSqlQuery "Parameter count mismatch"
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery "Parameter count mismatch"

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 406 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.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by U7Development
    #1

    Hi!!.
    this error is what i get while i qDebug() the query lastError()
    This is how i'm updating my record:

     QSqlQuery consulta;
        consulta.prepare("UPDATE tUsuario SET "
                         "rut = ?, nombre = ?, telefono = ?, direccion = ?, email = ?, contrasena = ?"
                         "WHERE REG = 1");
    
        consulta.addBindValue(usuario.get_rut());
        consulta.addBindValue(usuario.get_nombre());
        consulta.addBindValue(usuario.get_telefono());
        consulta.addBindValue(usuario.get_direccion());
        consulta.addBindValue(usuario.get_email());
        consulta.addBindValue(usuario.get_contrasena());
    
        if (!consulta.exec())	
            qDebug() << consulta.lastError();
    
        db.close();
    

    I have tried with QSqlQuery::bindValue function too, using the ":parameter" notation with the same result… what do i'm missing?

    Note that REG is the primary key autoincrement and unique, so i think i need to exclude in the sql instruction, or not?
    Thanks!

    JonBJ jsulmJ 2 Replies Last reply
    0
    • U U7Development

      Hi!!.
      this error is what i get while i qDebug() the query lastError()
      This is how i'm updating my record:

       QSqlQuery consulta;
          consulta.prepare("UPDATE tUsuario SET "
                           "rut = ?, nombre = ?, telefono = ?, direccion = ?, email = ?, contrasena = ?"
                           "WHERE REG = 1");
      
          consulta.addBindValue(usuario.get_rut());
          consulta.addBindValue(usuario.get_nombre());
          consulta.addBindValue(usuario.get_telefono());
          consulta.addBindValue(usuario.get_direccion());
          consulta.addBindValue(usuario.get_email());
          consulta.addBindValue(usuario.get_contrasena());
      
          if (!consulta.exec())	
              qDebug() << consulta.lastError();
      
          db.close();
      

      I have tried with QSqlQuery::bindValue function too, using the ":parameter" notation with the same result… what do i'm missing?

      Note that REG is the primary key autoincrement and unique, so i think i need to exclude in the sql instruction, or not?
      Thanks!

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

      @U7Development said in QSqlQuery "Parameter count mismatch":

                       "rut = ?, nombre = ?, telefono = ?, direccion = ?, email = ?, contrasena = ?"
                       "WHERE nombre = miNombre");
      

      Missing space character at end of first line or start of second line :) So it's passing

      contrasena = ?WHERE nombre = miNombre
      
      mrjjM 1 Reply Last reply
      3
      • JonBJ JonB

        @U7Development said in QSqlQuery "Parameter count mismatch":

                         "rut = ?, nombre = ?, telefono = ?, direccion = ?, email = ?, contrasena = ?"
                         "WHERE nombre = miNombre");
        

        Missing space character at end of first line or start of second line :) So it's passing

        contrasena = ?WHERE nombre = miNombre
        
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @JonB
        Nice catch !

        1 Reply Last reply
        0
        • U U7Development

          Hi!!.
          this error is what i get while i qDebug() the query lastError()
          This is how i'm updating my record:

           QSqlQuery consulta;
              consulta.prepare("UPDATE tUsuario SET "
                               "rut = ?, nombre = ?, telefono = ?, direccion = ?, email = ?, contrasena = ?"
                               "WHERE REG = 1");
          
              consulta.addBindValue(usuario.get_rut());
              consulta.addBindValue(usuario.get_nombre());
              consulta.addBindValue(usuario.get_telefono());
              consulta.addBindValue(usuario.get_direccion());
              consulta.addBindValue(usuario.get_email());
              consulta.addBindValue(usuario.get_contrasena());
          
              if (!consulta.exec())	
                  qDebug() << consulta.lastError();
          
              db.close();
          

          I have tried with QSqlQuery::bindValue function too, using the ":parameter" notation with the same result… what do i'm missing?

          Note that REG is the primary key autoincrement and unique, so i think i need to exclude in the sql instruction, or not?
          Thanks!

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @U7Development To add to @JonB : you can use https://doc.qt.io/qt-5/qsqlquery.html#executedQuery to see how the query looked like when it was executed, can help to find such issues.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

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