📄 connection.cpp
字号:
// Connection.cpp: implementation of the CConnection class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Course.h"
#include "Connection.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CConnection::CConnection()
{
}
CConnection::~CConnection()
{
}
void CConnection::open(){
try{
conn.CreateInstance(_uuidof(Connection));
conn->ConnectionTimeout=10;
conn->Open("Provider=OraOLEDB.Oracle.1;Password=liangcha;Persist Security Info=True;User ID=system;Data Source=Course","","",adModeUnknown);
}
catch(_com_error *e)
{
CString errer;
errer.Format("出错:%s",e->ErrorMessage());
AfxMessageBox(errer);
}
}
bool CConnection::close(){
if(conn->State){
conn->Close();
conn=NULL;
AfxMessageBox("close db connection!");
return true;
}
return false;
}
_RecordsetPtr CConnection::execute(CString sql)
{
_RecordsetPtr rs=NULL;
try{
if(rs.CreateInstance(_uuidof(Recordset))==S_OK)
{
rs->Open(_bstr_t(sql),conn.GetInterfacePtr(),adOpenStatic, adLockOptimistic,adCmdText);
}
}
catch(_com_error *e){
AfxMessageBox(e->ErrorMessage());
}
return rs;
}
bool CConnection::executeUpdate(CString sql)
{
try
{
conn->Execute(_bstr_t(sql),NULL,adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->Description());
return FALSE;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -