connectiondb.cpp

来自「影碟出租系统 利用mfc编程 与数据库连接」· C++ 代码 · 共 74 行

CPP
74
字号
// ConnectionDB.cpp: implementation of the CConnectionDB class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Rent.h"
#include "ConnectionDB.h"

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

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

_ConnectionPtr CConnectionDB::ConnectionP=NULL;
CConnectionDB::CConnectionDB()
{

}

CConnectionDB::~CConnectionDB()
{

}

_ConnectionPtr CConnectionDB::Connectiondb()
{
	HRESULT hr;
	try
	{
		hr=ConnectionP.CreateInstance(__uuidof(Connection));
		if(SUCCEEDED(hr))
		{
			hr=ConnectionP->Open("Provider=Microsoft.Jet.OLEDB.4.0;\
									Data Source=DVDMS.mdb","","",adModeUnknown);
			if(FAILED(hr))
			{
				AfxMessageBox("open fail");
				return NULL;
			}
		}
		else
		{
			AfxMessageBox("Createinstance of Connection fail!");
			return NULL;
		}
	}
	catch(_com_error e)
	{
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		AfxMessageBox(bstrSource+bstrDescription);
		return NULL;
	}
	
	return ConnectionP;
}

_ConnectionPtr CConnectionDB::GetConnectionPtr()
{
	return ConnectionP;
}

void CConnectionDB::DeleteConnectionPtr()
{
	ConnectionP->Close();
	ConnectionP=NULL;

}

⌨️ 快捷键说明

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