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. General Programming
  3. C / C++ / MFC
  4. C++ and ADO problem

C++ and ADO problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasec++question
6 Posts 3 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 hava a problem again executing an sql statment(INSERT) in my program can anyone help me find whats wrong? hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; 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"<//The program works up to here then it gives me an error:0x m_pConn->Execute(strSQL,NULL,adExecuteNoRecords); printf("Data Added Successfully\n",(LPCSTR)strSQL); m_pConn->Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); I wrote the program almost the same way as the sample code but still is not working the fiels in the db are DeptID: number Name: Text OfficeNo: number Phone: text DeptHead: text Any ideas? thanks a lot for all the help you gave me so far

    N E 2 Replies Last reply
    0
    • A antonaras

      Hi again I hava a problem again executing an sql statment(INSERT) in my program can anyone help me find whats wrong? hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; 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"<//The program works up to here then it gives me an error:0x m_pConn->Execute(strSQL,NULL,adExecuteNoRecords); printf("Data Added Successfully\n",(LPCSTR)strSQL); m_pConn->Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); I wrote the program almost the same way as the sample code but still is not working the fiels in the db are DeptID: number Name: Text OfficeNo: number Phone: text DeptHead: text Any ideas? thanks a lot for all the help you gave me so far

      N Offline
      N Offline
      NiceNaidu fo
      wrote on last edited by
      #2

      I Think, u r going wrong in framing the Insert Statement.

      antonaras wrote:

      printf("%s\n",(LPCSTR)strSQL);

      What is the output of the above line ??? Appu.. "If you judge people, you have no time to love them."

      A 2 Replies Last reply
      0
      • N NiceNaidu fo

        I Think, u r going wrong in framing the Insert Statement.

        antonaras wrote:

        printf("%s\n",(LPCSTR)strSQL);

        What is the output of the above line ??? Appu.. "If you judge people, you have no time to love them."

        A Offline
        A Offline
        antonaras
        wrote on last edited by
        #3

        Thanks for the reply NiceNaidu this is the output that i get: Insert into Dept(DeptID,Name,OfficeNo,Phone,DeptHead) Values(12Art25622491303Dr. Antonis Marcou Error:ΘX↔ Press any key to continue

        1 Reply Last reply
        0
        • N NiceNaidu fo

          I Think, u r going wrong in framing the Insert Statement.

          antonaras wrote:

          printf("%s\n",(LPCSTR)strSQL);

          What is the output of the above line ??? Appu.. "If you judge people, you have no time to love them."

          A Offline
          A Offline
          antonaras
          wrote on last edited by
          #4

          Hey NiceNaidu i got it you where right there was a problem with framing the values of the inser statment thanks for helping me out

          N 1 Reply Last reply
          0
          • A antonaras

            Hey NiceNaidu i got it you where right there was a problem with framing the values of the inser statment thanks for helping me out

            N Offline
            N Offline
            NiceNaidu fo
            wrote on last edited by
            #5

            Ok fine..keep going Appu.. "If you judge people, you have no time to love them."

            1 Reply Last reply
            0
            • A antonaras

              Hi again I hava a problem again executing an sql statment(INSERT) in my program can anyone help me find whats wrong? hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; 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"<//The program works up to here then it gives me an error:0x m_pConn->Execute(strSQL,NULL,adExecuteNoRecords); printf("Data Added Successfully\n",(LPCSTR)strSQL); m_pConn->Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); I wrote the program almost the same way as the sample code but still is not working the fiels in the db are DeptID: number Name: Text OfficeNo: number Phone: text DeptHead: text Any ideas? thanks a lot for all the help you gave me so far

              E Offline
              E Offline
              echozeng
              wrote on last edited by
              #6

              i think the program will throw a exception,you can look at the exception for finding out the error informtion.

              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