p; }
return FALSE;
}
// rs=new _RecordsetPtr;
HRESULT hr;
hr=rs->CreateInstance(__uuidof(Recordset));
if(FAILED(hr))
{
return FALSE;// 建立实例失败
}
hr=(*rs)->Open(sSQL,m_pConn->GetInterfacePtr(),
adOpenStatic, adLockBatchOptimistic, -1);
if(FAILED(hr))
{
return FALSE;// 打开连接失败
}
return TRUE;// 成功返回
}
catch(_com_error)
{
// AfxMessageBox(ce->Description());
ReportError(ErrFromOpenRecordset);
return FALSE;
}
catch()
{
MessageBox(NULL,"数据库记录打开失败!","记录失败",MB_OK|MB_ICONINFORMATION);
return FALSE;
}
return TRUE;
}
void CBBAdoConnection::CloseConnect()
{
try
{
if(m_pConn!=NULL)
{
if((*m_pConn)->State!=adStateClosed)
(*m_pConn)->Close();
delete m_pConn;
m_pConn=NULL;
}
}
catch(_com_error)
{
ReportError(ErrFormCloseConnection);
}
catch()
{
AfxMessageBox("关闭数据库连接未知错误!");
}
}
BOOL CBBAdoConnection::OpenConnection(CString strConnString, BOOL bReOpen)
{
char c[512];
strcpy(c,strConnString.GetBuffer(0));
strConnString.ReleaseBuffer();
return OpenConnection(c,bReOpen);
}
BOOL CBBAdoConnection::OpenRecordset(CString strSQL, _RecordsetPtr *rs, CString sConnString)
{
char c[1024];
strcpy(c,strSQL.GetBuffer(0));
strSQL.ReleaseBuffer();
return OpenRecordset(c,rs,(char*)(LPCTSTR)sConnString);
}
BOOL CBBAdoConnection::ExecuteTrans(CStringArray arrStrSQL) // 开始事务处理,不返回任何记录集,参数为事务SQL数组
{
(*m_pConn)->BeginTrans();
try
{
_RecordsetPtr* prsThis;
for(int i=0;i<arrStrSQL.GetSize();i++)
{
prsThis=new _RecordsetPtr;
OpenRecordset(arrStrSQL.ElementAt(i),prsThis);
delete prsThis;
}
prsThis=NULL;
(*m_pConn)->CommitTrans();
return TRUE;
}
catch(_com_error)
{
(*m_pConn)->RollbackTrans();
ReportError(ErrFormTanslation);
return FALSE;
}
}
// 执行SQL操作,不返回记录集
int CBBAdoConnection::ExecuteSQL(LPCSTR szSQL)
{
// VARIANT vEffect;
try
{
(*m_pConn)->Execute(szSQL,NULL,adCmdText|adExecuteNoRecords);
return TRUE;
}
catch(_com_error)
{
ReportError(ErrFormTanslation);
return FALSE;
}
// return vEffect.lVal;
}
// 返回是否处在连接状态
BOOL CBBAdoConnection::IsConnectClose()
{
return (m_pConn==NULL)||((*m_pConn)->State==adStateClosed);
}
// 设置连接超时
int CBBAdoConnection::SetConnTimeOut(long lTimeOut)
{
return (*m_pConn)