SQL SHOW NO RESULT
Unsolved
General and Desktop
-
I have a SQL command like this
QSqlQuery query(QSqlDatabase::database()); QString query_string = "SELECT person_name , person_family" "FROM ((person INNER JOIN contract_sit on person.person_contract_sit = contract_sit.contract_sit_id) " "INNER JOIN person_related on person.person_id = person_related.person_id) where person_related.contract_id = :contid"; query.prepare(query_string); query.bindValue(":contid", contid); query.exec();
and the code give no result in QTableView but when I change it to this:
QSqlQuery query(QSqlDatabase::database()); QString query_string = "SELECT *" "FROM ((person INNER JOIN contract_sit on person.person_contract_sit = contract_sit.contract_sit_id) " "INNER JOIN person_related on person.person_id = person_related.person_id) where person_related.contract_id = :contid"; query.prepare(query_string); query.bindValue(":contid", contid); query.exec();
the code works perfectly BTW both of SQL codes are working OK in SQL Management Studio.
-
@Codmasters I don't believe this SQL query will work.
Do you have checked the final query?if(!query.exec()) qDebug() << query.executedQuery();
I think you will see your error, I give you a hint, it have to do with spaces...
-
@Codmasters said in SQL SHOW NO RESULT:
the code works perfectly BTW both of SQL codes are working OK in SQL Management Studio.
Yes, but as @KroMignon says you will find you have not copied exactly what you have typed into SSMS into corresponding C++ string literals!