dbconnect.cpp

来自「自己编写的用户信息显示系统 包括了对数据库的简单操作 实现了连接」· C++ 代码 · 共 53 行

CPP
53
字号
// DBConnect.cpp: implementation of the CDBConnect class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "UserIn.h"
#include "DBConnect.h"

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

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

CDBConnect::CDBConnect()
{
	con.CreateInstance ("ADODB.Connection");
	Actived=false;
}

CDBConnect::~CDBConnect()
{
	con.Release ();
}
bool CDBConnect::Open (CString str)
{
	try
	{
		con->Open (_bstr_t(str),"","",adConnectUnspecified);
		Actived=true;
		return true;
	}
	catch(_com_error &e)
	{
		::AfxMessageBox (e.ErrorMessage ());
		for(long i=0;i<con->Errors ->Count ;i++)
		{
			AfxMessageBox(con->Errors ->GetItem (_variant_t(i))->Description );
		}
		return false;
	}

}
void CDBConnect::Close ()
{
	con->Close ();
	Actived=false;
}

⌨️ 快捷键说明

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