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. MySql Select statement

MySql Select statement

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • S Offline
    S Offline
    sahasrahla
    wrote on last edited by
    #1

    Hello,

    I'm new to QT and have trouble with my first application. I set up a mysql database connection which works perfectly fine for statements like "Update" and "Insert" but not for "Select".

    I want to check whether a specific data is already existing in my database:

    @QSqlQuery qry1(QSqlDatabase::database("Editor"));
    qry1.prepare("SELECT * FROM boardgame WHERE name='testspiel5'");
    int counter = 0;
    while(qry1.next())
    counter++;
    if(counter)
    already exists@

    I've also tried to use @if(qry1.first())@

    My counter is always zero but testspiel5 exists in my db. If I run the statement above directly in phpmyadmin it shows 1 row as expected. But not in my program.

    Best regards.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrho
      wrote on last edited by
      #2

      you need to run qry1.exec() first before you can read data from the query object

      2 hours of trial and error can save 10 minutes manual reading..

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sahasrahla
        wrote on last edited by
        #3

        Thank you chrho, that solved my issue!

        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