Qt QSqlQuery 的用法
最编程
2024-03-06 07:57:38
...
重点:
1.QSqlQuery可以进行sql语句的增删改查操作。
QSqlQuery query; //查询某个empNo的Memo和Photo字段的数据
query.prepare("select EmpNo, Memo, Photo from employee where EmpNo = :ID");
query.bindValue(":ID",empNo);
query.exec(); //其中exec表示执行sql语句。
query.first();//定位到第一条语句,如果有多条相似
QVariant va=query.value("Photo");
通过输入Id,获取特定的sql数据。
2.QSqlQuery由以下的构造函数
QSqlQuery(const QsqlDatabase &db)
QSqlQuery(constQString &query=QString(, constaSqlDatabase &db =QSqlDatabase())
不传递参数,表示使用默认的数据库进行链接。
void bindValue(const QString &placeholder, const QVariant &val, QSql::ParamType paramType = QSql.ln)
void bindValue(int pos, const QVariant &val, QSql:ParamType paramType = aSql.ln)
sql的bingValue方式有两种。
其一就是:
QSqlQuery query; //查询某个empNo的Memo和Photo字段的数据
query.prepare("select EmpNo, Memo, Photo from employee where EmpNo = :ID");
query.bindValue(":ID",empNo);
其二就是:
QSqlQuery query;
query.prepare("UPDATE employee SET Department=?, Salary=? WHERE EmpNo =?");
query.bindValue(0,"技术部”);
query.bindValue(1,5000);
query.bindValue(2,2006);
query.exec();
推荐阅读
-
iOS UISwitch 开关的基本用法
-
Qt6 网络关闭助手(引导版)的实现
-
Laravel 分布式唯一 ID 生成器的用法
-
Qt 模型视图代理对 QTableView 应用程序的简单介绍 - 二、设计思路
-
汇编语言中 cmp 指令用法的注释和摘要
-
Linux 学习] SSH 连接出现主机密钥验证失败的原因和解决方案以及 ssh-keygen 命令的用法
-
pandas ExcelWriter 的用法和代码示例
-
odoo中ondelete的用法
-
Qt5.14.2 适用于 Android 的首次编译未能解决问题(个人摘要版本)
-
63.QT-重写 QStackedWidget 以模仿 iPhone 的主页界面,实现左右滑动