为什么数据库输出的时候只有一条。数据库里面有好几条数据
QSqlDatabase dbconndb;
// for(int i=0;i<3;i++)
dbconndb =QSqlDatabase::database("first");//获得db1.
QSqlQuery query12(dbconndb);
int dbCount=0;
while(!dbconn.open()) {
}
query12.exec("select * from install");
while(query12.next()) {
// querycount++;
QString ele0;QString ele1;QString ele2;QString ele3;QString ele4;QString ele5;QString ele6;
QString ele7;QString ele8;
ele0=query12.value(0).toString();//query.value(0)是id的值,将其转换为int型
ele1=query12.value(1).toString();
ele2=query12.value(2).toString();
ele3=query12.value(3).toString();
ele4=query12.value(4).toString();
ele5=query12.value(5).toString();
ele6=query12.value(6).toString();
ele7=query12.value(7).toString();
ele8=query12.value(8).toString();
qDebug()<<ele0<<ele1<<ele2<<ele3<<ele4<<ele5<<ele6<<ele7<<ele8;//输出两个值
//if(ele8=="0"){
query12.prepare("UPDATE install SET upId=:a where upId='0'");
query12.bindValue(":a","1");
tableString tableBuff;
tableBuff.ele0=ele0;
tableBuff.ele1=ele1;
tableBuff.ele2=ele2;
tableBuff.ele3=ele3;
tableBuff.ele4=ele4;
tableBuff.ele5=ele5;
tableBuff.ele6=ele6;
tableBuff.ele7=ele7;
tableBuff.ele8=ele8;
tableStore.push_back(tableBuff);
// }
}
[最优解释]
query12.prepare("UPDATE install SET upId=:a where upId='0'");
请问install这个表的主键是哪个?
还有要加上建表的SQL,和insert数据的SQL语句,只看这些发现不了问题。
[其他解释]