www.pudn.com > Wgl.rar > WglAdo.cpp


// WglAdo.cpp: implementation of the WglAdo class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Wgl.h" 
#include "WglAdo.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
WglAdo::WglAdo() 
{ 
	  if(FAILED(m_pConnection.CreateInstance("ADODB.Connection"))) 
	  { 
		 AfxMessageBox("Create Instance failed!"); 
		return; 
	  } 
} 
 
WglAdo::~WglAdo() 
{ 
 
} 
BOOL WglAdo::GetConnection(CString strFilename) 
{ 
   CString str40="Provider=Microsoft.Jet.OLEDB.4.0;"; 
   CString strSource=str40+CString("Data Source=")+strFilename; 
   _bstr_t str (strSource); 
   try 
   { 
	   m_pConnection->Open((LPCTSTR) str, "","",adModeUnknown); 
   } 
   catch(_com_error  e) 
   { 
	AfxMessageBox("数据库连接失败,确认数据库是否在当前路径下!"); 
	return FALSE; 
   } 
   return TRUE; 
 
}