⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountado.cpp

📁 其中包含了ADO的多个实例
💻 CPP
字号:
// AccountAdo.cpp: implementation of the CAccountAdo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "account.h"
#include "AccountAdo.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAccountAdo::CAccountAdo()
{	
	::CoInitialize(NULL);
	m_pConnection = NULL;
	m_strConnection = _T("");
	m_pConnection.CreateInstance(__uuidof(Connection));
}

CAccountAdo::~CAccountAdo()
{
	if (m_pConnection!=NULL)
	{
		Close();
		m_pConnection = NULL;
		::CoUninitialize();
	}
}

bool CAccountAdo::Open(LPCTSTR lpstrConnection)
{	
	HRESULT hr = S_OK;

	if(IsOpen())
		Close();

	if(strcmp(lpstrConnection, _T("")) != 0)
		m_strConnection = lpstrConnection;

	ASSERT(!m_strConnection.IsEmpty());

	try
	{
		//m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Demo.mdb","","",adModeUnknown);
	
		hr = m_pConnection->Open(_bstr_t(m_strConnection), "", "", adModeUnknown);
		return hr == S_OK;
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
	}	
	return false;
}

bool CAccountAdo::IsOpen()
{
	if(m_pConnection)
		return m_pConnection->GetState() != adStateClosed;
	return false;
}

void CAccountAdo::Close()
{
	if(IsOpen())
		m_pConnection->Close();
}

bool CAccountAdo::Execute(LPCTSTR lpstrExec)
{
	ASSERT(m_pConnection != NULL);
	ASSERT(strcmp(lpstrExec, _T("")) != 0);

	try
	{
		m_pConnection->Execute(_bstr_t(lpstrExec), NULL, adExecuteNoRecords);
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
	}
	return true;
}

void CAccountAdo::dump_com_error(_com_error &e)
{
	CString ErrorStr;	
	
	_bstr_t bstrSource(e.Source());
	_bstr_t bstrDescription(e.Description());
	ErrorStr.Format( "CADODataBase Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
		e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
	m_strLastError = _T("Connection String = " + GetConnectionString() + '\n' + ErrorStr);
	#ifdef _DEBUG
		AfxMessageBox( ErrorStr, MB_OK | MB_ICONERROR );
	#endif
}

_ConnectionPtr CAccountAdo::GetActiveConnect()
{
	if(IsOpen())
		return m_pConnection;
	return 0;
}

//--------------------------------  add by lizhongya 2003.3.23

int CAccountAdo::AccountSave(LPCTSTR lpcDate)
{
	return 1;
}

int CAccountAdo::CheckConsumeDate(LPCTSTR lpcDate)
{
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -