1. 程式人生 > >【原創】<Debug> not positioned on a valid record

【原創】<Debug> not positioned on a valid record

否則 string name ora input body style deb 解決

Problem】

QSqlQuery::value: not positioned on a valid record

QSqlQuery :: value:未定位在有效記錄上

Solution】

參考鏈接 http://zhouyang340.blog.163.com/blog/static/302409592012101210525236/

解決方法:

QSqlQuery返回的數據集,record是停在第一條記錄之前的。所以,獲得數據集後,必須執行next()或first()到第一條記錄,這時候record才是有效的。否則,exec完直接value肯定報這個錯

QSqlQuery query;

query.prepare("select id,name from employee where name like :inputName");

query.bindValue(":inputName",str);

query.exec();

// QString namestr=query.value(1).toString(); //如果這句放在這裏的話出現上述錯誤

if(query.first())

{

QString namestr=query.value(1).toString(); //放在此處則正確

emit searchButton_clicked(namestr);

}

【原創】<Debug> not positioned on a valid record