Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Parameter count mismatch
Forum Updated to NodeBB v4.3 + New Features

Parameter count mismatch

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 4 Posters 561 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.
  • D Offline
    D Offline
    Designer23
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @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
      1
      • sierdzioS sierdzio

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

        D Offline
        D Offline
        Designer23
        wrote on last edited by
        #3

        @sierdzio yes a mixage of letters and integers

        JonBJ 1 Reply Last reply
        0
        • D Designer23

          @sierdzio yes a mixage of letters and integers

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

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

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

            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
            2

            • Login

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