?? adodb.cpp
字號:
// AdoDB.cpp: implementation of the CAdoDB class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "AdoDB.h"
#include "SysMod.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAdoDB::CAdoDB()
{
m_pConn = NULL;
}
CAdoDB::~CAdoDB()
{
CloseDB();
}
BOOL CAdoDB::OpenDB(CString strSRC)
{
if (!CloseDB())
return FALSE;
if (!ConnectDB(m_pConn,strSRC))
return FALSE;
return TRUE;
}
BOOL CAdoDB::OpenAccessDB(CString strFileName)
{
if (!FileExists(strFileName))
{
CString strMsg = "數(shù)據(jù)庫" + strFileName + "不存在!";
AfxMessageBox(strMsg);
return FALSE;
}
CString strSRC = GetAccessDBSRC(strFileName);
return OpenDB(strSRC);
}
BOOL CAdoDB::OpenAccessDB(CString strFileName,CString strPWD)
{
if (!FileExists(strFileName))
{
CString strMsg = "數(shù)據(jù)庫" + strFileName + "不存在!";
AfxMessageBox(strMsg);
return FALSE;
}
CString strSRC = GetAccessDBSRC(strFileName,strPWD);
return OpenDB(strSRC);
}
BOOL CAdoDB::CloseDB()
{
if (m_pConn != NULL)
{
m_pConn->Close();
m_pConn.Release();
m_pConn = NULL;
}
return TRUE;
}
BOOL CAdoDB::Execute(CString strSQL)
{
return ExecuteSQL(m_pConn,strSQL);
}
_RecordsetPtr CAdoDB::ExecuteRec(CString strSQL)
{
_bstr_t bstrSQL(strSQL);
_variant_t vRecsAffected(0L);
_RecordsetPtr pRcd = NULL;
try
{
pRcd = m_pConn->Execute(bstrSQL, &vRecsAffected, adOptionUnspecified);
}
catch(CException* pEx)
{
CString strMsg;
char pszError[256];
pEx->GetErrorMessage (pszError,256);
strMsg = pszError;
AfxMessageBox(strMsg);
return NULL;
}
catch(...)
{
CString strErrMsg;
strErrMsg = "數(shù)據(jù)庫操作錯誤!\n";
strErrMsg += strSQL;
AfxMessageBox(strErrMsg);
return NULL;
}
return pRcd;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -