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. {SOLVED} QSql obtain a specific value from the table
Forum Updated to NodeBB v4.3 + New Features

{SOLVED} QSql obtain a specific value from the table

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.4k Views 1 Watching
  • 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    QSql is a news for me ......
    But I open correctly my db (with error test), insert correcly my data, update correctly too .... but have some problem with these piece of code:

    @ int p = 0;
    QSqlQuery qy(db);
    qy.prepare("SELECT id_pro1 FROM program WHERE pro1 = :pro1)");
    qy.bindValue(":pro1", "ffff");
    qy.exec();
    qy.next();
    p = qy.record().toInt();
    ui->lcdNumber_2->display(p);
    qy.clear();@

    I tray some method ( .value, .arg) but obtain only p=0 ..... I dont Understand why.

    bkt

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SergioDanielG
      wrote on last edited by
      #2

      Hi gfxx.
      Try using @p = qy.value(0).toInt();
      @
      (based on "QSqlQuery::record()":http://qt-project.org/doc/qt-5.0/qtsql/qsqlquery.html#record )

      Insteads of @p = qy.record().toInt();
      @

      Regards.

      www.ftatv.com.ar El foro argentino de la TV libre

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mcosta
        wrote on last edited by
        #3

        Hi,

        line 7 of your code is WRONG; chage it with
        @
        p = qy.value (0).toInt();
        @

        to access to Query result you must use QSqlQuery::value(), QSqlQuery::record() is used to inspect result structure (column count, data types, ....)

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply
        0
        • gfxxG Offline
          gfxxG Offline
          gfxx
          wrote on last edited by
          #4

          tanks for the answer .... but code return only
          @p = 0@
          ..... but in table id_pro1 value are:
          @ id_pro1 = 28@

          I have other update and insert in these void .... and all work good ..... I have only one select in these file and not work properly ......

          Some idea??

          bkt

          1 Reply Last reply
          0
          • gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by
            #5

            MY BIG MISTAKE ......

            in my code I have added these line at the end:

            @qDebug() << p;@

            and obtain these messages ....

            @QSqlQuery::value: not positioned on a valid record@

            If control my code at the line 3 .....

            @ qy.prepare("SELECT id_pro1 FROM program WHERE pro1 = :pro1)");@

            the ")" caracters is a mistake .... now the code work perfect

            Tank you at all.

            bkt

            1 Reply Last reply
            0

            • Login

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