我试图通过使用WHERE和所选元素的ID从表列中获取一个值,但;查询->值(0(";始终返回0。
float dbSqlQueries::selectMoviePrice(QSqlDatabase db, QTableView *tableview){
float priceValue;
QString FetchedID = FetchIDSelectedInTable(tableview);
qDebug() << "MovieID"<<FetchedID;
QSqlQuery *query = new QSqlQuery(db);
query->prepare("SELECT rentcostperday FROM public.Movies WHERE movieid =" + FetchedID);
query->exec();
query->next();
priceValue = query->value(0).toFloat();
qDebug() <<"Selected price:"<< priceValue;
return priceValue;}
MovieID "1"
Selected price: 0
MovieID "3"
Selected price: 0
MovieID "1"
Selected price: 0
MovieID "10"
Selected price: 0
Postgres查询返回正确的值。我应该如何解决这个问题?
尝试用query->first()
替换query->next()