当前位置:网站首页>QT link MSSQL
QT link MSSQL
2022-07-27 21:04:00 【hitzsf】
Qt link MSSQL
List of articles
Reference article :
Microsoft ODBC The driver 17 for SQL Server Connection Strings - ConnectionStrings.com
The first 1 Ways of planting
Configure local ODBC Source
Reference article : Qt Connect SQL server database _Bruce-XIAO The blog of -CSDN Blog _qt Connect sqlserver
Matching code :
// The first method
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("localhost");
db.setDatabaseName("mssql"); // Set data source name
db.setUserName("SYSTEM");
db.setPassword("SYSTEM123,.");
The first 2 Ways of planting
have access to SQL Server Link string to achieve , The way is as follows
#include <QtWidgets>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlRecord>
bool OpenDatabase()
{
/* The first method QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setHostName("localhost"); db.setDatabaseName("mssql"); // Set data source name db.setUserName("sqluser"); db.setPassword("password"); */
/* The second method Link string */
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName(QString("DRIVER={SQL SERVER};"
"SERVER=%1;" // Server name
"DATABASE=%2;"// Database name
"UID=%3;" // Login name
"PWD=%4;" // password
)
.arg("192.168.1.207")
.arg("SCADA_AVIC_SERVER")
.arg("SYSTEM")
.arg("SYSTEM123,.")
);
bool ok=db.open();
if(ok)
{
qDebug()<<" Open database successfully ";
}
else
{
qDebug()<<" Failed to open database ";
}
return ok;
}
bool queryTable(QString tableName)
{
QString sql = "select * from %1";
sql = sql.arg (tableName);
QSqlQuery query;
query.exec (sql);
int i = 0;
qDebug() << query.size () << query.record ().count ();
auto record = query.record ();
QStringList colNames;
for (int i = 0; i < record.count (); ++i) {
colNames << QString("%1: ").arg (i,3,10,QChar('0')) + record.fieldName (i);
}
qDebug() << colNames.join (" , ");
while(query.next ()){
QStringList rowRecord;
rowRecord << (QString("%1").arg (++i,4,10,QChar('0')));
for (int j = 0; j < record.count (); ++j) {
rowRecord << query.value (j).toString ();
}
auto string = rowRecord.join (" ");
qDebug() << string;
}
qDebug() << query.size ();
return query.size ();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv); // This line can't be less
OpenDatabase();
queryTable("T_S_BASE_USER");
return 0;
}
summary
Obviously 2 This way will be better , There is no need to configure local ODBC Source .
边栏推荐
- knife4j通过js动态刷新全局参数
- R语言使用dplyr包左连接两个dataframe数据(left join)
- LeetCode每日一练 —— 21. 合并两个有序链表
- IOU 目标跟踪其一:IOU Tracker
- sql编码bug
- UE5使用DLSS(超级采样)提升场景的 FPS 远离卡顿的优化方案
- [today in history] July 27: model testing pioneer was born; Microsoft acquires qdos; The first laser typesetting Chinese newspaper
- Openresty Lua resty DNS domain name resolution
- 重复的DNA序列[hash判定重复+滑动窗口+二进制编码之位运算]
- hcip第五天
猜你喜欢

“收割”NFT:200元淘宝买图,上链卖30万元
![[numpy] array index and slice](/img/ce/34db7aef3fefe8a03e638d0838492f.png)
[numpy] array index and slice

82.(cesium篇)cesium点在3d模型上运动

Hexagon_ V65_ Programmers_ Reference_ Manual(7)

NPDP | what kind of product manager can be called excellent?

一文读懂Plato&nbsp;Farm的ePLATO,以及其高溢价缘由

Hexagon_V65_Programmers_Reference_Manual(7)

How to translate the address in the program?

SLIM:自监督点云场景流与运动估计(ICCV 2021)

Hexagon_V65_Programmers_Reference_Manual(5)
随机推荐
最新版web漏洞扫描工具AppScan\AWVS\Xray安装及使用教程
《SRE:Google运维解密》读后有感
[dart] a programming language for cross end development
Sscanf caused the address to be out of bounds
Rk3399 platform development series explanation (process part) 15.36, understanding process and collaboration process
SRE相关问题答疑
二舅,为什么火了?
获取委托中注册的方法
Global styles and icons
LeetCode每日一练 —— 206. 反转链表
Hexagon_V65_Programmers_Reference_Manual(9)
飞信卒于2022:中国移动一手好牌被打烂,5亿用户成“僵尸”
记一次restTemplate.getForEntity携带headers失败,restTemplate. exchange
Kingbasees heterogeneous database migration guide (2. Overview)
如何让个性化推荐即刻触达?云原生数据库GaussDB(for Redis)来助力
How to make personalized recommendations instantly accessible? Cloud native database gaussdb (for redis) to help
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用deviance函数计算出模型的残差平方和
ELK太重?试试KFC日志采集
go --- air自动重新编译
R语言使用dplyr包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组均值(mean)并合并生成的统计数据到原数据集中