-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectsql.h
38 lines (34 loc) · 1 KB
/
connectsql.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef CONNECTSQL_H
#define CONNECTSQL_H
#include <QtSql/QSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlQueryModel>
#include <QSql>
#include <QSqlDatabase>
#include <QSqlError>
#include<QSqlQuery>
#include<QDebug>
static bool sqlconnect(const QString &dbname)
{
QSqlDatabase db;
if(QSqlDatabase::contains("qt_sql_default_connection"))//in case connect to the QODBC many times
db = QSqlDatabase::database("qt_sql_default_connection");
else
db = QSqlDatabase::addDatabase("QODBC");
// QString dsn ="DRIVER={SQL SERVER};SERVER=10.2.18.135;DATABASE=";
// db.setDatabaseName(dsn+dbname);
// db.setUserName("sa");
// db.setPassword("1226");
QString dsn ="DRIVER={SQL SERVER};SERVER=bubble-PC;DATABASE=";
db.setDatabaseName(dsn+dbname);
db.setUserName("sa");
db.setPassword("xks137");
if(!db.open())
{
qDebug()<< "error="<<db.lastError().text();
return false;
}
return true;
}
#endif // CONNECTSQL_H