Delete record return strange error!
I am trying to delete a record. I am getting the error:
{"Operation is not allowed when the object is closed." (1)}
The following is the code used:
BOOL CCustomAdo::DeleteRecord(const _bstr_t bstrQuery)
{
BOOL bDeleted = FALSE;
HRESULT hr;
_RecordsetPtr pRecordset;
_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;
if(m_bIsConnectionOpen)
{
try
{
hr = pRecordset.CreateInstance(__uuidof(Recordset));
if(SUCCEEDED(hr))
{
pRecordset->PutRefActiveConnection(GetConnection());
hr = pRecordset->Open(_variant_t(bstrQuery), vNull, adOpenForwardOnly,
adLockOptimistic, adCmdText);
if(SUCCEEDED(hr))
{
if(!pRecordset->GetadoEOF()) //Getting the error here which doesn't make sence to me.
//if hr == SUCCEEDED, should I really be getting this error?
{
pRecordset->Delete(adAffectCurrent);
bDeleted = TRUE;
pRecordset->Close();
}
}
}
}
catch(_com_error &e)
{
_bstr_t bstrError = e.Error();
_bstr_t bstrDesc = e.Description();
TRACE("\nError:\t" + bstrError + "\nDescription:\t" + bstrDesc);
bDeleted = FALSE;
}
catch(...)
{
bDeleted = FALSE;
}
}
return bDeleted;
}
Any help would be greatly appreciated!
Mike B

