c++ - QT select from mysql -
i'm beginner in qt. i'm using qt5 in ubuntu. want select columns table in mysql database 1 column(id) equal variable in integer type. should do? wrote code have error!
qsqlquery query; int k=10; query.exec("select name,family employees id='"+k+"'"); while(query.next()){ qdebug()<<query.value(0).tostring(); qdebug()<<query.value(1).tostring(); }
and error:
invalid operands of types 'const char*' , 'const char [2]' binary 'operator+' query.exec("select name,family employees id='"+k+"'");
i not familiar qt, simple google search return :
https://stackoverflow.com/a/15902962/4421474
so in case be:
qsqlquery query; query.prepare(qstring("select name,family employees id = :id")); query.bindvalue(":id", k); query.exec();
by way have typo "selecr
must "select
.
Comments
Post a Comment