#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;
}
时间: 2024-10-10 09:18:29