标签:
#ifndef CONNECTION
#define CONNECTION
#endif // CONNECTION
#include <QtSql/QtSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QMessageBox>
static bool creatConnection()
{
QSqlDatabase db =QSqlDatabase::addDatabase("QODBC");
QString dsn="DRIVER={SQL SERVER};SERVER=CQH-PC;DATABASE=BookManage";
db.setHostName("127.0.0.1");
db.setDatabaseName(dsn);
db.setUserName("sa");
db.setPassword("000000");
if(!db.open())
{
QMessageBox::critical(0,QObject::tr("Database Error"),db.lastError().text());
return false;
}
return true;
}
标签:
原文地址:http://www.cnblogs.com/cqhstyle/p/4777517.html