Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Parameter count mismatch



  • 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);
    

  • Moderators

    @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?



  • @sierdzio yes a mixage of letters and integers



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



  • 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?


Log in to reply