qsqlquery.next()返回false,但数据库中的数据.为什么



我在SQLite数据库中具有数据。插入声明成功执行。但是,当想要从DB获取数据时,我什么也没发现,此错误" QSQLERROR(",","("。我已经检查了我的查询是活动的且无效。如何解决此问题?

这是我的代码:

void FindDialog::find()
{
    QString roll_number = ui->txt_RN->text ();
    int roll = roll_number.toInt ();
    const QString findstmnt = "SELECT Roll_Number, Name FROM student_info WHERE Roll_Number = :roll";
    scon->getQuery ()->prepare (findstmnt);
    scon->getQuery ()->bindValue ("roll", roll);
    if(scon->getQuery ()->exec ()){
        qDebug() << "Active: " << scon->getQuery ()->isActive ();
        qDebug() << "Valid: " << scon->getQuery ()->isValid ();
        if(scon->getQuery ()->isActive ()){
            if(scon->getQuery ()->next ()){
                qDebug() << "Has Data: " << scon->getQuery ()->next ();
            } else {
                qDebug() << scon->getQuery ()->lastError ();
            }
        }
    } else {
        qDebug() << scon->getQuery ()->lastError ();
    }

参数的名称不是roll,而是:roll

当您将值绑定到错误的参数名称时,实际参数具有其初始值,即NULL。因此,查询永远找不到任何行,因为没有值等于NULL

最新更新