4,011
社区成员
发帖
与我相关
我的任务
分享
// if(!m_pRecordset->Open(AFX_DB_USE_DEFAULT_TYPE, strSql))
m_pRecordset->Open(CRecordset::dynamic,strSql);
// if(!m_pRecordset->Open(CRecordset::dynaset ,strSql))
/// if(!m_pRecordset->Open(CRecordset::forwardOnly ,strSql))
EnterCriticalSection(&m_crit_db_Exec_section);
try
{
m_db.ExecuteSQL(strSql);
}
catch(CDBException* e)
{
char error[128] = {0};
e->GetErrorMessage(error,128,NULL);
error[strlen(error)-2] = 0;
TRACE("Insert GetErrorMessage: %s\n",error);
return FALSE;
}
LeaveCriticalSection(&m_crit_db_Exec_section);
_variant_t var;
var= m_pRecordset->GetCollect(_variant_t((long)index));
if(var.vt != VT_NULL)
strcpy(Retvar,(char*)(_bstr_t)var);
else
strcpy(Retvar, " ");
void CloseRecordSet()
{
if(m_pRecordset!=NULL)
m_pRecordset->Close();
}
这样判断也有问题?
//打开查询记录
_RecordsetPtr OPenRecordSet(_RecordsetPtr m_pRecordset,CString strsql)
{
bstr_t bstrSQL=strsql;
m_pRecordset.CreateInstance(__uuidof(Recordset));
//打开记录集
m_pRecordset->CursorType = adOpenStatic;
m_pRecordset->CursorLocation = adUseClient;
if ( m_pRecordset->State )// 如果记录集打开的话,把它关了
m_pRecordset->Close();
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenStatic, adLockOptimistic,adCmdText);
return m_pRecordset;
}
//获取想要的数据列
int GetColectEx(_RecordsetPtr m_pRecordset,char * Retvar,int index)
{
if(index<0)
return -1;
_variant_t var;
var= m_pRecordset->GetCollect(_variant_t((long)index)); ///在这里经常异常
if(var.vt != VT_NULL)
strcpy(Retvar,(char*)(_bstr_t)var);
else
strcpy(Retvar, " ");
return 1;
}
/////调用查询和获取数据
try
{
m_pRecordset=OPenRecordSet(m_pRecordset,strsql);
char temp[50]={0};
GetColectEx( m_pRecordset,temp,0);
iNum=atoi((char*)_bstr_t(temp));
CloseRecordSet();
}
catch(_com_error e)
{
e.Description();
return false;
}