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. Help with ADO and vc++-newbie [modified]

Help with ADO and vc++-newbie [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpc++announcement
10 Posts 4 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 everyone i'm trying to update a record of a db in access using ADO and the SQL update command the columns in the db are: token - text Spam - number Ham - number Pos - number (with decimal points) app- number in my program i have the following variables for each of the columns _bstr_t token; int valField2; int valField3; double valField4; int valField5; i try this code but i get an error at runtime pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam="+vlaField2; command+=",Pos="+valField4; command+=",app="+valField5; command+="WHERE token='"+ token; command+="'"; _bstr_t strSQLstatment=command.c_str(); variant_t vntRecordAffected; m_pConn->Execute(strSQLstatment,&vntRecordAffected,adCmdText); i get the following error Error:¦¨¨m¨V //i have no idea what this means but this is what i get if i try to update with spacific numbers instead of using variables it works fine pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam=10,Pos=0.43,app=10 WHERE token='"+ token; command+="'"; Any ideas what might be wrong. Do i need to convert all variables that are to be inserted to type _bstr_t; Please help me i really need to find this out thanks a lot

    2 V D 3 Replies Last reply
    0
    • A antonaras

      Hi everyone i'm trying to update a record of a db in access using ADO and the SQL update command the columns in the db are: token - text Spam - number Ham - number Pos - number (with decimal points) app- number in my program i have the following variables for each of the columns _bstr_t token; int valField2; int valField3; double valField4; int valField5; i try this code but i get an error at runtime pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam="+vlaField2; command+=",Pos="+valField4; command+=",app="+valField5; command+="WHERE token='"+ token; command+="'"; _bstr_t strSQLstatment=command.c_str(); variant_t vntRecordAffected; m_pConn->Execute(strSQLstatment,&vntRecordAffected,adCmdText); i get the following error Error:¦¨¨m¨V //i have no idea what this means but this is what i get if i try to update with spacific numbers instead of using variables it works fine pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam=10,Pos=0.43,app=10 WHERE token='"+ token; command+="'"; Any ideas what might be wrong. Do i need to convert all variables that are to be inserted to type _bstr_t; Please help me i really need to find this out thanks a lot

      2 Offline
      2 Offline
      224917
      wrote on last edited by
      #2

      Can you log the strSQLstatment just before passing to the execute method.


      suhredayan
      There is no place like 127.0.0.1

      A 1 Reply Last reply
      0
      • 2 224917

        Can you log the strSQLstatment just before passing to the execute method.


        suhredayan
        There is no place like 127.0.0.1

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

        Thanks for the reply suhredayan® i'm sorry i'm not very good with ADO what to you mean by log the strSQLstatment? thanks again

        2 1 Reply Last reply
        0
        • A antonaras

          Thanks for the reply suhredayan® i'm sorry i'm not very good with ADO what to you mean by log the strSQLstatment? thanks again

          2 Offline
          2 Offline
          224917
          wrote on last edited by
          #4

          antonaras wrote:

          i'm sorry i'm not very good with ADO what to you mean by log the strSQLstatment

          Can you print the the content of strSQLstatment somewhere and see any problem with the it before passing to the Execute method.


          suhredayan
          There is no place like 127.0.0.1

          A 1 Reply Last reply
          0
          • A antonaras

            Hi everyone i'm trying to update a record of a db in access using ADO and the SQL update command the columns in the db are: token - text Spam - number Ham - number Pos - number (with decimal points) app- number in my program i have the following variables for each of the columns _bstr_t token; int valField2; int valField3; double valField4; int valField5; i try this code but i get an error at runtime pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam="+vlaField2; command+=",Pos="+valField4; command+=",app="+valField5; command+="WHERE token='"+ token; command+="'"; _bstr_t strSQLstatment=command.c_str(); variant_t vntRecordAffected; m_pConn->Execute(strSQLstatment,&vntRecordAffected,adCmdText); i get the following error Error:¦¨¨m¨V //i have no idea what this means but this is what i get if i try to update with spacific numbers instead of using variables it works fine pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam=10,Pos=0.43,app=10 WHERE token='"+ token; command+="'"; Any ideas what might be wrong. Do i need to convert all variables that are to be inserted to type _bstr_t; Please help me i really need to find this out thanks a lot

            V Offline
            V Offline
            Viorel
            wrote on last edited by
            #5

            Since valField variables are of integer type, expressions like ",Pos=" + valField4 seem to be problematic. Do you see the error when you compile the program, or when the program runs?

            A 1 Reply Last reply
            0
            • 2 224917

              antonaras wrote:

              i'm sorry i'm not very good with ADO what to you mean by log the strSQLstatment

              Can you print the the content of strSQLstatment somewhere and see any problem with the it before passing to the Execute method.


              suhredayan
              There is no place like 127.0.0.1

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

              Hey suhredayan® thanks for the reply when i output the strSQLstatement i get: ictionary SET Spam=,Pos=☺s=WHERE token='pill'//is totally messed up Error:Θ·╒ Press any key to continue and the output of strSQLstatment when i use fixed numbers looks good UPDATE tblDictionary SET Spam=10,Pos=0.43,app=10 WHERE token='pill' Press any key to continue Can u see why this happens cause i have no clue thanks again

              2 1 Reply Last reply
              0
              • V Viorel

                Since valField variables are of integer type, expressions like ",Pos=" + valField4 seem to be problematic. Do you see the error when you compile the program, or when the program runs?

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

                Thanks for the reply Viorel it compiles ok no errors at runtime i get an error if u see the discusion above i show the output from strSQLstatment and it seems problematic can u see why

                1 Reply Last reply
                0
                • A antonaras

                  Hey suhredayan® thanks for the reply when i output the strSQLstatement i get: ictionary SET Spam=,Pos=☺s=WHERE token='pill'//is totally messed up Error:Θ·╒ Press any key to continue and the output of strSQLstatment when i use fixed numbers looks good UPDATE tblDictionary SET Spam=10,Pos=0.43,app=10 WHERE token='pill' Press any key to continue Can u see why this happens cause i have no clue thanks again

                  2 Offline
                  2 Offline
                  224917
                  wrote on last edited by
                  #8

                  use sprintf() to format the command string.


                  suhredayan
                  There's no place like 127.0.0.1

                  A 1 Reply Last reply
                  0
                  • 2 224917

                    use sprintf() to format the command string.


                    suhredayan
                    There's no place like 127.0.0.1

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

                    Hey suhredayan® can u help me with using sprintf() sprintf(strSQLstatment,command) is this correct ?

                    1 Reply Last reply
                    0
                    • A antonaras

                      Hi everyone i'm trying to update a record of a db in access using ADO and the SQL update command the columns in the db are: token - text Spam - number Ham - number Pos - number (with decimal points) app- number in my program i have the following variables for each of the columns _bstr_t token; int valField2; int valField3; double valField4; int valField5; i try this code but i get an error at runtime pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam="+vlaField2; command+=",Pos="+valField4; command+=",app="+valField5; command+="WHERE token='"+ token; command+="'"; _bstr_t strSQLstatment=command.c_str(); variant_t vntRecordAffected; m_pConn->Execute(strSQLstatment,&vntRecordAffected,adCmdText); i get the following error Error:¦¨¨m¨V //i have no idea what this means but this is what i get if i try to update with spacific numbers instead of using variables it works fine pCommand->ActiveConnection = m_pConn; command="UPDATE tblDictionary SET Spam=10,Pos=0.43,app=10 WHERE token='"+ token; command+="'"; Any ideas what might be wrong. Do i need to convert all variables that are to be inserted to type _bstr_t; Please help me i really need to find this out thanks a lot

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      antonaras wrote:

                      _bstr_t strSQLstatment=command.c_str();

                      Set a breakpoint here. What is the value of command?


                      "The largest fire starts but with the smallest spark." - David Crow

                      "Judge not by the eye but by the heart." - Native American Proverb

                      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