Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Parameter count mismatch

    Tools
    4
    5
    234
    Loading More Posts
    • 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.
    • D
      Designer23 last edited by

      I wrote this code and i got an error "Parameter count mismatch", btw, I connect successfully to the database. how to solve it?
      this is the code :

      db = QSqlDatabase::addDatabase("QSQLITE");  //this is the driver for SQL Lite
          db.setPort(3306);
          db.setHostName("sql2.freemysqlhosting.net");
          db.setPassword("*****");
          db.setUserName("sql2****");
          if(!db.open())
              ui->label->setText("<font color='red'>Failed to connect to database.</font>");
          else
              ui->label->setText("<font color='green'>Connected to database and Opened.</font>");
      
      
      qsr.prepare("INSERT INTO  mytab(machine_id, operator_id) VALUES(?,?);");
          qsr.addBindValue(ui->lineEdit->text());
          qsr.addBindValue(ui->lineEdit_Operator_ID->text());
          if(qsr.exec())
              QMessageBox::information(this, "State","Saved",QMessageBox::Ok);
          else
              QMessageBox::information(this, "State", qsr.lastError().text(),QMessageBox::Ok);
      
      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        @Designer23 said in Parameter count mismatch:

        "Parameter count mismatch"

        SQLite shows this error for basically any error that occurs :-( Syntax, parameter count, parameter types - all kinds of things can trigger it.

        Are machine_id and operator_id really strings, not integers?

        (Z(:^

        D 1 Reply Last reply Reply Quote 1
        • D
          Designer23 @sierdzio last edited by

          @sierdzio yes a mixage of letters and integers

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @Designer23 last edited by

            @Designer23
            Show the definition (including columns) of table mytab.

            1 Reply Last reply Reply Quote 0
            • M
              mchinand last edited by

              Are you missing a call to QSqlDatabase::setDatabaseName? Are you actually trying to connect to a Mysql database (guessing based on the port number) instead of a SqlLite database?

              1 Reply Last reply Reply Quote 2
              • First post
                Last post