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

📄 connection.cpp

📁 库存管理系统 用来管理仓库的
💻 CPP
字号:
#include "StdAfx.h"
#include "Connection.h"

CConnection::CConnection(CString strConnection)
{
   AfxOleInit();
   conn=NULL;
   m_strConnection=strConnection;
}

CConnection::~CConnection()
{
}
bool CConnection::Open()
{   
	try
	{
		HRESULT hcon;
		HRESULT result;
		hcon=conn.CreateInstance(_uuidof(Connection));
		if(hcon==S_OK)
			result=conn->Open(_bstr_t(m_strConnection),"","",0);
		if(result==S_OK)
			return true;
	}
	catch(_com_error e)
	{
        AfxMessageBox("连接数据库出错!");
	}
	return false;
}

bool CConnection::Close()
{
	if(isConnected())
	{
	  conn->Close();
	  conn=NULL;
      AfxMessageBox("关闭数据库!");
	  return true;
	}
	return false;
}

_RecordsetPtr CConnection::Execute(CString strSql)
{
	_RecordsetPtr rs=NULL;
	try
	{
		if(rs.CreateInstance(_uuidof(Recordset))==S_OK)
		{

			rs->Open(_variant_t(strSql),conn.GetInterfacePtr(),adOpenDynamic, adLockOptimistic,adCmdText); 
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
    return rs;
}
bool CConnection::isConnected()
{
	if(conn->State)
		return true;
	else 
		return false;
}
bool CConnection::executeUpdate(CString strSql)
{
	try
	{
		conn->Execute(_bstr_t(strSql),NULL,adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->Description());
		return false;
	}
	return true;
}

⌨️ 快捷键说明

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