📄 connectdb.cpp
字号:
// ConnectDB.cpp: implementation of the CConnectDB class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SPSS.h"
#include "ConnectDB.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CConnectDB::CConnectDB()
{
TRY
{
// m_db.OpenEx("DSN=fanglei;", CDatabase::noOdbcDialog );
CString sDriver = "Microsoft Access Driver (*.mdb)";
CString sFile = GetExeDictionary()+"Data.mdb";
CString sDsn;
sDsn.Format("DRIVER={%s};DBQ=%s",sDriver,sFile);
m_db.OpenEx(sDsn);
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CMemoryException, pEx)
{
pEx->ReportError();
AfxMessageBox("Memory Exception!");
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError, 100);
AfxMessageBox(szError);
}
END_CATCH
// m_pRecordset = new CRecordset(&m_db);
}
CConnectDB::~CConnectDB()
{
m_db.Close();
}
CString CConnectDB::GetExeDictionary()
{
//获得当前程序目录(.exe)
TCHAR szFilePath[MAX_PATH+1];
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(_tcsrchr(szFilePath, _T('\\')))[1] = 0;
CString str_url = szFilePath;
return str_url;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -