lueStr(char* cVal,CString strIndex,int nFieldLen=-1);
GetValueLong(long *lVal, LPCSTR lpszIndex);
BOOL GetValueFloat(float* fVal,CString strIndex);
BOOL GetValueStr(CString& str,LPCSTR lpszFieldName,int nFieldLen=-1);
BOOL GetValueStr(CString& str,UINT nFieldIndex,int nFieldLen=-1);
BOOL GetValueStr(CString& str,_variant_t &vIndex,int nFieldLen=-1);
// 判断值是否有效,是否为NULL
BOOL VerifyVTData(_variant_t& value);
BOOL VerifyVTData(char* pData);
protected:
_RecordsetPtr* m_prsThis;
_ConnectionPtr* m_pConn;
void ReportError();
};
#endif // _BBADOCONNECT_H
////CPP文件
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBBAdoConnection::CBBAdoConnection()
{
m_pConn=NULL;
}
_ConnectionPtr* CBBAdoConnection::GetConnection()
{
return m_pConn;
}
CString CBBAdoConnection::GetConnString()
{
return m_szConnString;
}
CBBAdoConnection::~CBBAdoConnection()
{
// 关比连接
CloseConnect();
}
BOOL CBBAdoConnection::OpenConnection(char *sConnString,BOOL bReOpen /*=FALSE*/)
{
// 不需重新打开
if(!bReOpen)
{
if(m_pConn !=NULL && ((*m_pConn)->State!=adStateClosed))
return TRUE;
}
VERIFY(sConnString);
strcpy(m_szConnString,sConnString);
try
{
m_pConn =new _ConnectionPtr;
m_pConn->CreateInstance(__uuidof(Connection));
if(m_pConn==NULL)
return FALSE;
HRESULT hr=(*m_pConn)->Open((char*)sConnString,"","",-1);
if(FAILED(hr))
return FALSE;
return TRUE;
}
catch(_com_error)
{
ReportError(ErrFormOpenConnsction);
return FALSE;
}
catch()
{
#ifdef _DEBUG // 调试时显示相应的错误信息
MessageBox(NULL,"数据库连接未处理的异常!","连接失败",MB_OK|MB_ICONINFORMATION);
#else
MessageBox(NULL,"连接数据失败,请检查网络和数据库设置是否正确","连接失败",MB_OK|MB_ICONINFORMATION);
#endif
return FALSE;
}
SetConnTimeOut(5);
}
BOOL CBBAdoConnection::OpenRecordset(const char *sSQL, _RecordsetPtr *rs, char *sConnString)
{
// rs=new _RecordsetPtr;
VERIFY(sSQL);
try
{
if((m_pConn==NULL)||((*m_pConn)->State==adStateClosed))
{
int n=(*m_pConn)->State;
if(sConnString!=NULL)
{
if(!OpenConnection(sConnString))
return FALSE;
}
// 尝试连接数据库
else
{
//
// if(!OpenConnection(m_szConnString))
// return FALSE;
// MessageBox(NULL,"数据库连接已经断开,请重新连接!","连接
问题",MB_OK|MB_ICONINFORMATION);
&nbs