Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SQL SHOW NO RESULT
Forum Updated to NodeBB v4.3 + New Features

SQL SHOW NO RESULT

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 310 Views
  • 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 Offline
    C Offline
    Codmasters
    wrote on last edited by aha_1980
    #1

    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.

    KroMignonK JonBJ 2 Replies Last reply
    0
    • C Codmasters

      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.

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @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
      7
      • C Codmasters

        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.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

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

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved