MySql Select statement



  • 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.



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



  • Thank you chrho, that solved my issue!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.