Results 1 to 3 of 3

Thread: SQLite What am i doing wrong?

  1. #1

    Default SQLite What am i doing wrong?

    Qt Code:
    1. int row;
    2. open conn...
    3. QSqlQuery qry;
    4. qry.prepare("select rowid from my_table");
    5. qry.exec();
    6. while(qry.next()){
    7. if(something==something2)
    8. row=qry.value(0).toInt();
    9. }
    10. close conn...
    11. QString some;
    12. open conn...
    13. qry.prepare("UPDATE my_table"
    14. "SET some=:some"
    15. "WHERE rowid=:row");
    16.  
    17. qry.bindValue(":some", some);
    18. qry.bindValue(":row",row);
    19.  
    20. if(qry.exec()){
    21.  
    22. ...
    23. close conn...
    24. }
    25.  
    26. else{
    27. QMessageBox::critical(this,tr("error::"),qry.lastError().text());
    28. close conn...
    29. }
    To copy to clipboard, switch view to plain text mode 

    i rly don't understand what am i doing wrong...
    note that my sql connections are working fine, ...

    i keep getting error "no query unable to fetch row"

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SQLite What am i doing wrong?

    When reporting errors it is generally useful to specify where you get the error.

    I guess line 13 or maybe 20. The qry object is associated withthe default database connection at the time the query was constructed. You close that connection at 'line' 10 so the qry object is no longer associated with a connection and you get the error when you try to use the connection.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SQLite What am i doing wrong?

    I am curious how you got the lines "open conn..." and "close conn..." to compile. If you're going to post code and ask us questions about it, at least post real code.

    Here's a hint: How does the QSqlQuery you have created know what database to use when executing the query? Where have you told it anything about the database?

Similar Threads

  1. What am i doing wrong?
    By ayanda83 in forum Newbie
    Replies: 3
    Last Post: 2nd January 2013, 09:58
  2. QTableView, sqlite, wrong data type
    By bzqt in forum Newbie
    Replies: 1
    Last Post: 10th October 2011, 23:56
  3. What am I doing wrong??
    By Splatify in forum Newbie
    Replies: 3
    Last Post: 7th February 2011, 16:47
  4. what is wrong with my qt ?
    By lwb422 in forum Qt Programming
    Replies: 5
    Last Post: 12th April 2010, 14:07
  5. [Qt][SQLite] Two problems with SQLite.
    By Xandareva in forum Newbie
    Replies: 6
    Last Post: 6th April 2010, 23:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.