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. Database & SysAdmin
  3. Database
  4. Pls Help - Visual C++ with ADO

Pls Help - Visual C++ with ADO

Scheduled Pinned Locked Moved Database
helpc++databasedebugging
2 Posts 2 Posters 0 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.
  • A Offline
    A Offline
    antonaras
    wrote on last edited by
    #1

    Hi again I'm trying to connect to an access db using ADO i use some sample codes to perform a simple SELECT query and display them through a recordset. I've tryed really hard to make it work i've searched everywhere pls help me find the problem. This is the code i use:: #include #include #include #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") void main(int argc, char* argv[]) { HRESULT hr = S_OK; _ConnectionPtr m_pConn; try { HRESULT hr = m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =ADOTestDB.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; pCommand->CommandText = "Select Name,Dept From Student"; _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Name")->Value; valField2 = pRecordset->Fields->GetItem("Dept")->Value.intVal; printf("%d - %s\n",valField2,(LPCSTR)valField1); pRecordset->MoveNext(); } } }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } m_pConn->Close(); } i get an exeption "Can't create an intance of ADO.Connection" and the i asks if i want to debug Pls help me i'm trying a lot to connect to a db and enything i do seems to be wrong and the truth is that everytime i post a msg about C++ and ADO no one replies. pls i'm desparate

    G 1 Reply Last reply
    0
    • A antonaras

      Hi again I'm trying to connect to an access db using ADO i use some sample codes to perform a simple SELECT query and display them through a recordset. I've tryed really hard to make it work i've searched everywhere pls help me find the problem. This is the code i use:: #include #include #include #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") void main(int argc, char* argv[]) { HRESULT hr = S_OK; _ConnectionPtr m_pConn; try { HRESULT hr = m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =ADOTestDB.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; pCommand->CommandText = "Select Name,Dept From Student"; _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Name")->Value; valField2 = pRecordset->Fields->GetItem("Dept")->Value.intVal; printf("%d - %s\n",valField2,(LPCSTR)valField1); pRecordset->MoveNext(); } } }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } m_pConn->Close(); } i get an exeption "Can't create an intance of ADO.Connection" and the i asks if i want to debug Pls help me i'm trying a lot to connect to a db and enything i do seems to be wrong and the truth is that everytime i post a msg about C++ and ADO no one replies. pls i'm desparate

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      This might be helpful: http://www.codeproject.com/database/WittmerADO.asp[^] -- modified at 17:30 Tuesday 30th May, 2006

      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