Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

prepare functions fails.



  • Hello all;
    I have this prepare function that refuses to co-operate, any help
    I have been reading docs and websites all day .... even tried my son for help.

    the code is::

    test1 = qry.prepare("INSERT INTO histories (datum, hsname, dist)" " VALUES (:histStr[1], :histStr[0], :histInt[0])");

    qry.bindValue(":datum", histStr[1]);
    qry.bindValue(":hsname", histStr[0]);
    qry.bindValue(":dist", histInt[0]);

    where test1 is a bool that remains false.

    Regards.
    Frik Brits


  • Lifetime Qt Champion

    Hi and welcome to the forums
    The last part looks odd
    " VALUES (:histStr[1], :histStr[0], :histInt[0])");
    You should use the bind variable names and not real variable name ( the var where values in )

    QSqlQuery query;
    query.prepare("INSERT INTO person (id, forename, surname) VALUES (:id, :forename, :surname)");
    query.bindValue(":id", 1001);
    query.bindValue(":forename", "Bart");
    query.bindValue(":surname", "Simpson");
    query.exec();
    


  • Hello "mrjj",
    Ahhh and there the lights come on for me too :)
    Thank you so much.

    I am a little of a newbie with this bindValue(); but now I get it I think.

    Regards
    Frik Brits


Log in to reply