Results 1 to 4 of 4

Thread: How to get value from a query statement ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2011
    Posts
    14
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get value from a query statement ?

    Thanks you very much, I done.

    Qt Code:
    1. QSqlQuery q("select count(MaDaiLy) as SoDaiLyTrongQuan from DaiLy, Quan where DaiLy.Quan_TenQuan = Quan.TenQuan and Quan.TenQuan = '" + ui.cbTenQuan->currentText() + "'");
    2. QSqlRecord rec = q.record();
    3. int nameCol = rec.indexOf("SoDaiLyTrongQuan"); // index of the field "name"
    4. q.next();
    5. int SoDLHienCoTrongQuan = q.value(nameCol).toInt();
    To copy to clipboard, switch view to plain text mode 

    the result is return: 2

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to get value from a query statement ?

    Hi, since you only query one "field" the index is 0. Thus you can simplify your code:
    Qt Code:
    1. QSqlQuery q("select count(MaDaiLy) from DaiLy, Quan where DaiLy.Quan_TenQuan = Quan.TenQuan and Quan.TenQuan = '" + ui.cbTenQuan->currentText() + "'");
    2. q.next();
    3. int SoDLHienCoTrongQuan = q.value(0).toInt();
    To copy to clipboard, switch view to plain text mode 
    Further have a look at QSqlQuery::bindValue().

Similar Threads

  1. Help with QT, SQLite, Update Statement
    By chetu1984 in forum Newbie
    Replies: 3
    Last Post: 17th March 2011, 22:24
  2. Replies: 7
    Last Post: 3rd March 2011, 14:32
  3. Replies: 3
    Last Post: 22nd January 2011, 13:08
  4. confusion with a STATEMENT used frequently
    By salmanmanekia in forum Newbie
    Replies: 3
    Last Post: 11th June 2008, 20:54
  5. SmartFOSS Mission Statement
    By travlr in forum Qt-based Software
    Replies: 0
    Last Post: 16th April 2007, 05:41

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.