Qt 中SQL语句通配符

来源:互联网 发布:sql数据库存储过程 编辑:程序博客网 时间:2024/05/16 09:41
int gdt_dataDB::updatePatien(const PatientInfo& Patien)
{
    QString strSql;
    QSqlQuery query(m_db);
    strSql.append(QString("UPDATE patienInformation SET name = ?, sex = ?, age = ? WHERE number = ?"));
    query.prepare(strSql);
    query.bindValue(0,QVariant(Patien.name));
    query.bindValue(1,QVariant(Patien.gender));
    query.bindValue(2,QVariant(Patien.age));
    query.bindValue(3,QVariant(Patien.patient_id));
    if(query.exec())
    {
        return 1;
    }
    else
    {
        qDebug()<<query.lastError().text();
        return 0;
    }

}

我直接使用?为通配符,在调用bindValue时,按照SQL语句中?出现的位置,依次绑定各个位置上的值。

原创粉丝点击