Mysql with Qt query [solved]
-
wrote on 14 Mar 2014, 18:45 last edited by
Hello Forum,
i have a question about MYSQL Syntax in Qt. I have a table with the name "min5_1" an i have problems with the query.
The Code:
@ MainWindow main;
this->comboxLaden();
QString tableName = ui->tablesBox->currentText();
qDebug() << tableName;
QSqlQueryModel *model = new QSqlQueryModel();
QSqlQuery *qry = new QSqlQuery(main.mydb1);
qry->prepare("SELECT * FROM '"+tableName+"' ");
if(qry->exec())
{
qDebug() << "If schleife";
model->setQuery(*qry);
ui->anzeigenView->setModel(model);
}
else
qDebug() << "Else" << qry->exec();@The exec is always false. When i changed the var "tableName" to "min5_1" the query is true. What doing false?
Alex
-
wrote on 15 Mar 2014, 12:38 last edited by
Try to add:
@
qDebug() << "SELECT * FROM '"+tableName+"' ";
qDebug() << "SELECT * FROM 'min5_1' ";
@
Hopefully, you will see the difference and reason for the misbehaviour. -
wrote on 15 Mar 2014, 13:43 last edited by
try to debug the error, something like:
@qDebug() << qry->lastError()->text();@
-
wrote on 15 Mar 2014, 15:51 last edited by
Thank you for the help. I have a syntax error
@
qry->prepare("select * from "+tableName+"");@
2/4