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. Parameter Count Mismatch
Forum Updated to NodeBB v4.3 + New Features

Parameter Count Mismatch

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 5 Posters 1.8k Views
  • 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.
  • jsulmJ jsulm

    @Aromakc Print out https://doc.qt.io/qt-5/qsqlquery.html#executedQuery after executing the query to see how the actual query looks like.
    Also, you use different casing in the column list: is this a mistake?
    (username,password,Name,Gender,Address,Phone_Number)

    A Offline
    A Offline
    Aromakc
    wrote on last edited by
    #3

    @jsulm (username,password,Name,Gender,Address,Phone_Number) is the name of my columns that I have creaed all being string except Phone_Number
    While I add qDebug()<< query.lastQuery(); before if(que
    r.exec()) it shows:
    "INSERT into Users (username,password,Name,Gender,Address,Phone_Number) VALUES(?,?,?,?,?,?)"

    jsulmJ 1 Reply Last reply
    0
    • A Aromakc

      @jsulm (username,password,Name,Gender,Address,Phone_Number) is the name of my columns that I have creaed all being string except Phone_Number
      While I add qDebug()<< query.lastQuery(); before if(que
      r.exec()) it shows:
      "INSERT into Users (username,password,Name,Gender,Address,Phone_Number) VALUES(?,?,?,?,?,?)"

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

      @Aromakc said in Parameter Count Mismatch:

      before if

      AFTER executing the query...

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

      A 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Aromakc said in Parameter Count Mismatch:

        before if

        AFTER executing the query...

        A Offline
        A Offline
        Aromakc
        wrote on last edited by
        #5

        @jsulmScreenshot (43).png

        KroMignonK 1 Reply Last reply
        0
        • A Aromakc

          @jsulmScreenshot (43).png

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #6

          @Aromakc Maybe a silly question, but where did you define the database connection settings?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          A 1 Reply Last reply
          0
          • KroMignonK KroMignon

            @Aromakc Maybe a silly question, but where did you define the database connection settings?

            A Offline
            A Offline
            Aromakc
            wrote on last edited by
            #7

            @KroMignon I have created a database connection login.h

            QSqlDatabase mydb; // default connection
            void connClose(){
            mydb.close();
            mydb.removeDatabase(QSqlDatabase::defaultConnection); //closing db and removing any connection
            }
            bool connOpen()
            {
            QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE");
            mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db");
            if(!mydb.open()){
            qDebug()<<("Failed to locate database!");
            return false;
            }
            else {
            qDebug()<<("Connected..."); // qDebug("Connected");
            return true;
            }
            }
            i have liked login.h in another createaccount.h and coded
            Login conn;

            I think there is no problem creating two tables in databasename.db

            KroMignonK jsulmJ JonBJ 3 Replies Last reply
            0
            • A Aromakc

              @KroMignon I have created a database connection login.h

              QSqlDatabase mydb; // default connection
              void connClose(){
              mydb.close();
              mydb.removeDatabase(QSqlDatabase::defaultConnection); //closing db and removing any connection
              }
              bool connOpen()
              {
              QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE");
              mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db");
              if(!mydb.open()){
              qDebug()<<("Failed to locate database!");
              return false;
              }
              else {
              qDebug()<<("Connected..."); // qDebug("Connected");
              return true;
              }
              }
              i have liked login.h in another createaccount.h and coded
              Login conn;

              I think there is no problem creating two tables in databasename.db

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #8

              @Aromakc Please logout QSqlQuery::executedQuery() which is the real SQL statement which has been executed.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              2
              • A Aromakc

                @KroMignon I have created a database connection login.h

                QSqlDatabase mydb; // default connection
                void connClose(){
                mydb.close();
                mydb.removeDatabase(QSqlDatabase::defaultConnection); //closing db and removing any connection
                }
                bool connOpen()
                {
                QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE");
                mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db");
                if(!mydb.open()){
                qDebug()<<("Failed to locate database!");
                return false;
                }
                else {
                qDebug()<<("Connected..."); // qDebug("Connected");
                return true;
                }
                }
                i have liked login.h in another createaccount.h and coded
                Login conn;

                I think there is no problem creating two tables in databasename.db

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @Aromakc I was actually talking about https://doc.qt.io/qt-5/qsqlquery.html#executedQuery NOT lastQuery...

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

                1 Reply Last reply
                1
                • A Aromakc

                  @KroMignon I have created a database connection login.h

                  QSqlDatabase mydb; // default connection
                  void connClose(){
                  mydb.close();
                  mydb.removeDatabase(QSqlDatabase::defaultConnection); //closing db and removing any connection
                  }
                  bool connOpen()
                  {
                  QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE");
                  mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db");
                  if(!mydb.open()){
                  qDebug()<<("Failed to locate database!");
                  return false;
                  }
                  else {
                  qDebug()<<("Connected..."); // qDebug("Connected");
                  return true;
                  }
                  }
                  i have liked login.h in another createaccount.h and coded
                  Login conn;

                  I think there is no problem creating two tables in databasename.db

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

                  @Aromakc said in Parameter Count Mismatch:
                  These may not be relevant to your current issue, but:

                  mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db");

                  As pasted here, this is not at all right! I assume you have \\ in your actual code, but it shows as \ here since you did not put it inside code tags when pasting?

                  qint64 phone;
                  phone=ui->line_phone->text().toInt();
                  all being string except Phone_Number

                  This is a bad idea. A phone number is a string of digit characters, not a number/integer.

                  it shows parameter count mismatch

                  You should copy & paste the exact error message you receive, in case that gives us a clue.

                  How do we know your Users table has exactly 6 columns?

                  Also, looking at your screenshot, what are those "duplicate connection name" warnings about? Your code should be running without any such warnings.

                  1 Reply Last reply
                  3
                  • jsulmJ jsulm

                    @Aromakc Print out https://doc.qt.io/qt-5/qsqlquery.html#executedQuery after executing the query to see how the actual query looks like.
                    Also, you use different casing in the column list: is this a mistake?
                    (username,password,Name,Gender,Address,Phone_Number)

                    A Offline
                    A Offline
                    Aromakc
                    wrote on last edited by
                    #11

                    @jsulm
                    I coded qDebug()<<query.executedQuery(); it shows
                    "INSERT into Users (username,password,Name,Gender,Address,Phone_Number) VALUES(:a,:bb,:bc,:bd,:be,:bf)"

                    J.HilkJ 1 Reply Last reply
                    0
                    • A Aromakc

                      @jsulm
                      I coded qDebug()<<query.executedQuery(); it shows
                      "INSERT into Users (username,password,Name,Gender,Address,Phone_Number) VALUES(:a,:bb,:bc,:bd,:be,:bf)"

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #12

                      @Aromakc
                      Ok, try to clean up your query, you're mixing lowercase and capital keywords and don't terminate with a ;

                      query.prepare("INSERT INTO Users (username, password, Name, Gender, Address, Phone_Number) VALUES(?, ?, ?, ?, ? ,?);");


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      1
                      • JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #13

                        I have posted above questions like "How do we know your Users table has exactly 6 columns?`, but no response.

                        So my last comment is I would try

                        SELECT  username, password, Name, Gender, Address, Phone_Number from Users
                        

                        Up to @Aromakc whether he bothers...

                        A JonBJ 2 Replies Last reply
                        1
                        • JonBJ JonB

                          I have posted above questions like "How do we know your Users table has exactly 6 columns?`, but no response.

                          So my last comment is I would try

                          SELECT  username, password, Name, Gender, Address, Phone_Number from Users
                          

                          Up to @Aromakc whether he bothers...

                          A Offline
                          A Offline
                          Aromakc
                          wrote on last edited by Aromakc
                          #14

                          @JonB Here is screenshot of my db and i have changed phone to string to see if it is the problem. Did you mean this or sth else?
                          I fixed those duplicate connection name. It was left there as I was testing my database connectivity.
                          Screenshot (48).png

                          KroMignonK 1 Reply Last reply
                          0
                          • JonBJ JonB

                            I have posted above questions like "How do we know your Users table has exactly 6 columns?`, but no response.

                            So my last comment is I would try

                            SELECT  username, password, Name, Gender, Address, Phone_Number from Users
                            

                            Up to @Aromakc whether he bothers...

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

                            @Aromakc
                            I never suggested the phone number type would be the cause of your issue. But I am pleased you have altered its type off numeric.

                            @JonB said in Parameter Count Mismatch:

                            SELECT username, password, Name, Gender, Address, Phone_Number from Users

                            I suggested you try the above from your Qt program (query.exec()). This may help us identify where your INSERT problem comes from.

                            A 1 Reply Last reply
                            0
                            • A Aromakc

                              @JonB Here is screenshot of my db and i have changed phone to string to see if it is the problem. Did you mean this or sth else?
                              I fixed those duplicate connection name. It was left there as I was testing my database connectivity.
                              Screenshot (48).png

                              KroMignonK Offline
                              KroMignonK Offline
                              KroMignon
                              wrote on last edited by
                              #16

                              @Aromakc As @JonB already asked you: have you fixed the sqlite db filepath?

                              mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db"); // Bad escape sequence
                              mydb.setDatabaseName("D:/Retailhub/Retailhub/items.db"); // correct
                              mydb.setDatabaseName("D:\\Retailhub\\Retailhub\\items.db"); // also correct
                              

                              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                              JonBJ A 2 Replies Last reply
                              3
                              • KroMignonK KroMignon

                                @Aromakc As @JonB already asked you: have you fixed the sqlite db filepath?

                                mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db"); // Bad escape sequence
                                mydb.setDatabaseName("D:/Retailhub/Retailhub/items.db"); // correct
                                mydb.setDatabaseName("D:\\Retailhub\\Retailhub\\items.db"); // also correct
                                
                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #17

                                @KroMignon
                                I don't think this is the OP's situation (else he'd get other errors). I tested, and if you type \\ into a post here without code tagging, it comes out as \ when displayed. Which I'm sure is the situation for his case.

                                1 Reply Last reply
                                0
                                • KroMignonK KroMignon

                                  @Aromakc As @JonB already asked you: have you fixed the sqlite db filepath?

                                  mydb.setDatabaseName("D:\Retailhub\Retailhub\items.db"); // Bad escape sequence
                                  mydb.setDatabaseName("D:/Retailhub/Retailhub/items.db"); // correct
                                  mydb.setDatabaseName("D:\\Retailhub\\Retailhub\\items.db"); // also correct
                                  
                                  A Offline
                                  A Offline
                                  Aromakc
                                  wrote on last edited by Aromakc
                                  #18

                                  @KroMignon Yes. Thats not the problem. / and (backslash) both works. I will try to manage connection problem creating new project and update here.

                                  1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @Aromakc
                                    I never suggested the phone number type would be the cause of your issue. But I am pleased you have altered its type off numeric.

                                    @JonB said in Parameter Count Mismatch:

                                    SELECT username, password, Name, Gender, Address, Phone_Number from Users

                                    I suggested you try the above from your Qt program (query.exec()). This may help us identify where your INSERT problem comes from.

                                    A Offline
                                    A Offline
                                    Aromakc
                                    wrote on last edited by
                                    #19

                                    @JonB
                                    I have created "Users" table after creating "Inventory" table in items.db from Sqlite Studio. Using another database manager software I could see Both Tables in items.db but
                                    if(query.exec(Select username........ from Users)) showed Users is unavailable.
                                    I used sqlite3 from terminal and it showed Error: No such Tables: Users
                                    So I deleted Users from Sqlite Studio and entered new Users table from terminal and it Worked.

                                    (I will look more into Sqlite Studio as changes made into Inventory form the same app worked.)

                                    Thank you and other contributors.

                                    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