Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Accessing a _RecordsetPtr returned by ATL in ASP

Accessing a _RecordsetPtr returned by ATL in ASP

Scheduled Pinned Locked Moved Web Development
c++databasehelptutorialquestion
2 Posts 2 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 3472
    wrote on last edited by
    #1

    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.

    R 1 Reply Last reply
    0
    • U User 3472

      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.

      R Offline
      R Offline
      Rick Benish
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups