Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved SQL SHOW NO RESULT

    General and Desktop
    3
    3
    132
    Loading More Posts
    • 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.
    • C
      Codmasters last edited by aha_1980

      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.

      KroMignon JonB 2 Replies Last reply Reply Quote 0
      • KroMignon
        KroMignon @Codmasters last edited by

        @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...

        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 Reply Quote 7
        • JonB
          JonB @Codmasters last edited by

          @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!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post