cannot Excecute query in sql
-
i just cant execute the query
databaseconnection:
QSqlDatabase Logindb=QSqlDatabase::addDatabase("QMYSQL","MyConnect");
Logindb.setHostName("127.0.0.1");
Logindb.setPort(3306);
Logindb.setDatabaseName("agr_kako");
Logindb.setUserName("root");
Logindb.setPassword("1234");on pushbutton:
QString username,passwort; username=ui->lineEdit_User->text(); passwort=ui->lineEdit_Password->text(); QSqlQuery qry(QSqlDatabase::database("MyConnect")); if(Logindb.open()) { QSqlQuery qry(QSqlDatabase::database("MyConnect")); qry.prepare(QString("SELECT * FROM login WHERE Username=:username and Password :passwort ")); qry.bindValue(":username",username); qry.bindValue(":passwort",passwort); if(!qry.exec()){ QMessageBox::information(this,"Failed","Query Failed to Execute"); } else { while(qry.next()){ QString usernameFromDB=qry.value(1).toString(); QString passwordFromDB=qry.value(2).toString(); if(username==username&& passwordFromDB==passwort) {QMessageBox::information(this,"Success","Login Erfolgreich"); parameter=new Parameter(this); parameter->show(); hide(); } else { QMessageBox::information(this,"Fehler","Name oder Passwort falsch");} } } }
// if(Logindb.open()){
// if(qry.exec("Select * from login where Username='"+username+"'and Password'"+passwort+"'"))
// {
// int count=0;
// while(qry.next())
// {// count++;
// }
// if(count==1)
// ui->label_3->setText("Login erfolgreich");
// if(count>1)
// ui->label_3->setText("");
// if(count==1)
// ui->label_3->setText("Login fehlgeschlagen Passwort oder Name falsch");
// }
// }
else
{
QMessageBox::information(this,"Failed","Query Failed to Execute");
return;
} -
Hi
Try to see if it has some error information using query.lastError() -
@JonnyQB said in cannot Excecute query in sql:
qry.prepare(QString("SELECT * FROM login WHERE Username=:username and Password :passwort "));
You mean
Password=:passwort
, just like you did forUsername=:username
. Please try to look at your code before posting a question on it. -
-
Hi,
Start your application with QT_DEBUG_PLUGINS environment variable set to 1 so see what happens when the plugins are loaded.
You can set that variable in the Run part of the Project panel.
-