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. update a table in a database

update a table in a database

Scheduled Pinned Locked Moved C / C++ / MFC
databaseperformancehelpquestionannouncement
5 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.
  • Z Offline
    Z Offline
    zizzzz
    wrote on last edited by
    #1

    Hi, I have a question I want to update my table with values like this CString valuestr="('"+m_comm+"','"+m_sp+"')"; CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr; database.ExecuteSQL(req); And I have an error: non valide use of '!','.',or'()' in expression "%S'('COM4','9600')'

    L D S 3 Replies Last reply
    0
    • Z zizzzz

      Hi, I have a question I want to update my table with values like this CString valuestr="('"+m_comm+"','"+m_sp+"')"; CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr; database.ExecuteSQL(req); And I have an error: non valide use of '!','.',or'()' in expression "%S'('COM4','9600')'

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      zizzzz wrote:

      CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr;

      What is %s in your query? I do not believe that format specifiers are allowed in queries. You might be better off rewriting your query as : CString req; req.Format("UPDATE T_Port SET CommPort='%s', Speed='%s'", m_comm, m_sp); database.Execute(req);

      Z 1 Reply Last reply
      0
      • L Lost User

        zizzzz wrote:

        CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr;

        What is %s in your query? I do not believe that format specifiers are allowed in queries. You might be better off rewriting your query as : CString req; req.Format("UPDATE T_Port SET CommPort='%s', Speed='%s'", m_comm, m_sp); database.Execute(req);

        Z Offline
        Z Offline
        zizzzz
        wrote on last edited by
        #3

        thank's a lot ;)

        1 Reply Last reply
        0
        • Z zizzzz

          Hi, I have a question I want to update my table with values like this CString valuestr="('"+m_comm+"','"+m_sp+"')"; CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr; database.ExecuteSQL(req); And I have an error: non valide use of '!','.',or'()' in expression "%S'('COM4','9600')'

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

          zizzzz wrote:

          CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr;

          The %s would only be valid if you were using CString::Format().


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

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

          1 Reply Last reply
          0
          • Z zizzzz

            Hi, I have a question I want to update my table with values like this CString valuestr="('"+m_comm+"','"+m_sp+"')"; CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr; database.ExecuteSQL(req); And I have an error: non valide use of '!','.',or'()' in expression "%S'('COM4','9600')'

            S Offline
            S Offline
            S Douglas
            wrote on last edited by
            #5

            This is method is ripe for SQL injection attacks. This will never work. CString req="UPDATE T_Port SET CommPort='%s', Speed=' s'"+valuestr; Try something like this.

            CString req=_T(“”);

            req.Format(_T("UPDATE T_Port SET CommPort='%s', Speed=' s'"), valuestr);

            But first read this article about dealing with SQL injection attacks SQL Injection Attacks and Some Tips on How to Prevent Them[^]


            I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

            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