query.exec("CREATE TABLE players("
"id INTEGER PRIMARY KEY,"
"name TEXT NOT NULL, "
"password TEXT NOT NULL, "
"state INTEGER NOT NULL)");
query.prepare("SELECT MAX(id) FROM players");
if(!query.exec())
{
qDebug()<<query.lastError();//--------->QSqlError("", "Unable to fetch row", "No query")
}
else
{
while(query.next())
{
maxid=query.value(0).toInt();
qDebug()<<maxid;
}
}
query.prepare("SELECT * FROM players"
"WHERE name = :name");
query.bindValue(":name",ch1);
query.exec();
if(!query.exec())
{
qDebug()<< query.lastError();//--------->QSqlError("", "Parameter count mismatch", "")
qDebug()<<"1";
}
else
2 个解决方案
#1
当我换了个写法后
QString sql = "SELECT * FROM players(name)values(%1)";
query.prepare(sql.arg(ch1));
这时候错误又由 QSqlError("", "Parameter count mismatch", "") 变成了 QSqlError("", "Unable to fetch row", "No query")
实在被这个弄得 云里雾里= =
QString sql = "SELECT * FROM players(name)values(%1)";
query.prepare(sql.arg(ch1));
这时候错误又由 QSqlError("", "Parameter count mismatch", "") 变成了 QSqlError("", "Unable to fetch row", "No query")
实在被这个弄得 云里雾里= =
#2
Where 后多了个空格
#1
当我换了个写法后
QString sql = "SELECT * FROM players(name)values(%1)";
query.prepare(sql.arg(ch1));
这时候错误又由 QSqlError("", "Parameter count mismatch", "") 变成了 QSqlError("", "Unable to fetch row", "No query")
实在被这个弄得 云里雾里= =
QString sql = "SELECT * FROM players(name)values(%1)";
query.prepare(sql.arg(ch1));
这时候错误又由 QSqlError("", "Parameter count mismatch", "") 变成了 QSqlError("", "Unable to fetch row", "No query")
实在被这个弄得 云里雾里= =
#2
Where 后多了个空格