Parameter Count Mismatch
-
@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(?,?,?,?,?,?)" -
-
@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
-
@Aromakc I was actually talking about https://doc.qt.io/qt-5/qsqlquery.html#executedQuery NOT lastQuery...
-
@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_NumberThis 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.
-
@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(?, ?, ?, ?, ? ,?);");
-
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...
-
@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.
-
@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 yourINSERT
problem comes from. -
-
@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. -
@KroMignon Yes. Thats not the problem. / and (backslash) both works. I will try to manage connection problem creating new project and update here.
-
@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.
12/19