Accessing a _RecordsetPtr returned by ATL in ASP
-
I have an ATL component that passes back an IDispatch of a _RecordsetPtr as the VT_DISPATCH of a VARIANT. e.g. STDMETHODIMP CBASE::GetRecordSet(BSTR sql, VARIANT *Result) { _variant_t vBuffer; ... vBuffer = static_cast(m_recordset); *Result = vBuffer.Detach(); } From my C++ MFC app I can call GetRecordSet() and access the recordset using the pdispVal of the VARIANT .... VARIANT Result; hr = IBaseInst->GetProfile( _bstr_t("SELECT name FROM emps"), &Result); _RecordsetPtr pRecordSet; pRecordSet = Result.pdispVal; if( !pRecordSet->adoEOF) { .... } I am trying to perform similar actions from an ASP page but do not know how to access the recordset correctly. I can access fields assuming they exist using: Dim rs rs = Ibase.GetRecordSet( "SELECT name FROM emps") gName = rs("name") But I can not do much else; rs.bof fails with 'Object doesn't support this property or method'. I obvioulsy need to do something to get at the recordset from the returned VARIANT, but what ? Can anyone help with suggestions or code examples.
-
I have an ATL component that passes back an IDispatch of a _RecordsetPtr as the VT_DISPATCH of a VARIANT. e.g. STDMETHODIMP CBASE::GetRecordSet(BSTR sql, VARIANT *Result) { _variant_t vBuffer; ... vBuffer = static_cast(m_recordset); *Result = vBuffer.Detach(); } From my C++ MFC app I can call GetRecordSet() and access the recordset using the pdispVal of the VARIANT .... VARIANT Result; hr = IBaseInst->GetProfile( _bstr_t("SELECT name FROM emps"), &Result); _RecordsetPtr pRecordSet; pRecordSet = Result.pdispVal; if( !pRecordSet->adoEOF) { .... } I am trying to perform similar actions from an ASP page but do not know how to access the recordset correctly. I can access fields assuming they exist using: Dim rs rs = Ibase.GetRecordSet( "SELECT name FROM emps") gName = rs("name") But I can not do much else; rs.bof fails with 'Object doesn't support this property or method'. I obvioulsy need to do something to get at the recordset from the returned VARIANT, but what ? Can anyone help with suggestions or code examples.
I see your using MFC but my ATL code should still help you STDMETHODIMP CDoc_Session::SQLSearch(BSTR bstrSQL, Recordset ** ppRecSet) { HRESULT hr; try { _bstr_t bstrSearch(bstrSQL); if(bstrSearch.length()>0) { _RecordsetPtr piRS; hr = piRS.CreateInstance(__uuidof(Recordset)); if(FAILED(hr)) return hr; piRS->CursorLocation = adUseClient; piRS->Open(bstrSearch, m_piConn->ConnectionString, adOpenForwardOnly,adLockReadOnly,adCmdUnknown); if(VARIANT_FALSE == piRS->GetADOEOF()) return piRS->QueryInterface(__uuidof(_Recordset), reinterpret_cast(ppRecSet)); else return E_FAIL; } else return E_FAIL; } catch (_com_error e) { ::MessageBox(NULL, e.Description(), "DNS", MB_OK); return e.Error(); } catch (...) { return E_FAIL; } return S_OK; } 1. You need to change your variant return value to a Recordset ** ppRecSet. You will need to do a #importlib of the msado15.dll in the library section of your .idl file. This is so the midl compiler will be able to marshell the Recordset type. 2. Next you need to make sure returning Recordset->CursorLocation=adUseClient; 3. Finally you need do a QueryInterface on the local Recordset so that can intialize the returing record set. If you need more help on this I think I might be able to find some old MFC code that does this same thing. Good Luck