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. sql Update command Error

sql Update command Error

Scheduled Pinned Locked Moved Database
databasehelpannouncement
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.
  • P Offline
    P Offline
    phowarso
    wrote on last edited by
    #1

    I have some sql Update command error. I get the following error message when i run my project. " ERROR [42000] [Microsoft] [ODBC Microsoft Access Driver] Syntax error in UPDATE statement " some of my code is following.... Dim CW As Integer Dim RCW As Integer ------------------------------------------------------------------------------------------------------------------------ Dim level As String = CStr(ComboBox1.SelectedItem.ToString) Dim exercise As String = CStr(ComboBox2.SelectedItem.ToString) Dim FWds As String = CStr(lblFalseWords.Text) Dim SpanTime As String = CStr(hour ) "UPDATE tblSave SET Level=' " & level & " ',Exercise=' " & exercise & " ',CWords=" & CW & ",FWords=' " & FWds & " ',WPM=" & RCW & ",SpanTime=' " & SpanTime & " ' WHERE tblSave.UserName=' " & CurrentUser & " ' " Please tell me some suggestion.....:confused:

    C S 2 Replies Last reply
    0
    • P phowarso

      I have some sql Update command error. I get the following error message when i run my project. " ERROR [42000] [Microsoft] [ODBC Microsoft Access Driver] Syntax error in UPDATE statement " some of my code is following.... Dim CW As Integer Dim RCW As Integer ------------------------------------------------------------------------------------------------------------------------ Dim level As String = CStr(ComboBox1.SelectedItem.ToString) Dim exercise As String = CStr(ComboBox2.SelectedItem.ToString) Dim FWds As String = CStr(lblFalseWords.Text) Dim SpanTime As String = CStr(hour ) "UPDATE tblSave SET Level=' " & level & " ',Exercise=' " & exercise & " ',CWords=" & CW & ",FWords=' " & FWds & " ',WPM=" & RCW & ",SpanTime=' " & SpanTime & " ' WHERE tblSave.UserName=' " & CurrentUser & " ' " Please tell me some suggestion.....:confused:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well my first suggestion is to read up on SQL injection attacks, to understand why you should never allow any system to use this code, ever. Next, I would point out that CW and RCW are used without you giving them a value. However, I'd say your core issue is simply that you're doing your own bit of SQL injection, that values in the strings you're passing through are what's causing this SQL to break. Did you go into the debugger to look at the final SQL string and see what the final SQL line looks like ? Perhaps if you copied and pasted it into SQL Server, it would explain it even better, but the solution is to use stored procs and pass your parameters in a sane way, not by string mashing

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • P phowarso

        I have some sql Update command error. I get the following error message when i run my project. " ERROR [42000] [Microsoft] [ODBC Microsoft Access Driver] Syntax error in UPDATE statement " some of my code is following.... Dim CW As Integer Dim RCW As Integer ------------------------------------------------------------------------------------------------------------------------ Dim level As String = CStr(ComboBox1.SelectedItem.ToString) Dim exercise As String = CStr(ComboBox2.SelectedItem.ToString) Dim FWds As String = CStr(lblFalseWords.Text) Dim SpanTime As String = CStr(hour ) "UPDATE tblSave SET Level=' " & level & " ',Exercise=' " & exercise & " ',CWords=" & CW & ",FWords=' " & FWds & " ',WPM=" & RCW & ",SpanTime=' " & SpanTime & " ' WHERE tblSave.UserName=' " & CurrentUser & " ' " Please tell me some suggestion.....:confused:

        S Offline
        S Offline
        ssurya4u
        wrote on last edited by
        #3

        In "tblSave" table, if CWords and WPM columns are of VarChar Datatype then you have to alter update query as below: 'UPDATE tblSave SET Level='" & level & "',Exercise='" & exercise & "',CWords='" & CW & "',FWords='" & FWds & "',WPM='" & RCW & "',SpanTime='" & SpanTime & "' WHERE tblSave.UserName='" & CurrentUser & "'" And For Level, Excercise, FWords and SpanTime columns ur giving one space after single quote, if the query runs successfully that space will also insert into the database.

        P 1 Reply Last reply
        0
        • S ssurya4u

          In "tblSave" table, if CWords and WPM columns are of VarChar Datatype then you have to alter update query as below: 'UPDATE tblSave SET Level='" & level & "',Exercise='" & exercise & "',CWords='" & CW & "',FWords='" & FWds & "',WPM='" & RCW & "',SpanTime='" & SpanTime & "' WHERE tblSave.UserName='" & CurrentUser & "'" And For Level, Excercise, FWords and SpanTime columns ur giving one space after single quote, if the query runs successfully that space will also insert into the database.

          P Offline
          P Offline
          phowarso
          wrote on last edited by
          #4

          Now i get success by adding [] in Level field. Now my success code is "UPDATE tblSave SET [Level]='" & level & "',Exercise='" & exercise & "',CWords=" & CW & ",FWords='" & FWds & "',WPM=' & RCW & ",SpanTime='" & SpanTime & "' WHERE tblSave.UserName='" & CurrentUser & "'" Plese tell me how do u think for above metter?

          B 1 Reply Last reply
          0
          • P phowarso

            Now i get success by adding [] in Level field. Now my success code is "UPDATE tblSave SET [Level]='" & level & "',Exercise='" & exercise & "',CWords=" & CW & ",FWords='" & FWds & "',WPM=' & RCW & ",SpanTime='" & SpanTime & "' WHERE tblSave.UserName='" & CurrentUser & "'" Plese tell me how do u think for above metter?

            B Offline
            B Offline
            buchstaben
            wrote on last edited by
            #5

            sounds like "Level" is a keyword and has to be put into [] if used as column.

            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