How to Fix Syntax error in UPDATE statementNested With Statement CrashesSyntax error in INSERT INTO Statement in vb.neterror database: Syntax error in INSERT INTO statementcommand error *incorrect syntax near ','*How to fix position of scroll bar to bottom in DataGridView?Error on UPDATE statement when savingVB 2010 error (INSERT INTO) syntax errorsyntax error in UPDATE statement vb.net/ MS access 2007Vb net update statement issuehow to use group by in select statement in vb.net

How bitcoin nodes update UTXO set when their latests blocks are replaced?

Is there a benefit to having both truesight and darkvision?

Array Stutter Implementation

Full backup on database creation

Command to Search for Filenames Exceeding 143 Characters?

Can't remember the name of this game

Plot twist where the antagonist wins

Source for parable about two fetuses

When do characters level up?

Why is desire the root of suffering?

When and what was the first 3D acceleration device ever released?

Ticket sales for Queen at the Live Aid

Is CD audio quality good enough for the final delivery of music?

Is there a way to make it so the cursor is included when I prtscr key?

General purpose replacement for enum with FlagsAttribute

Why are C64 games inconsistent with which joystick port they use?

Is floating in space similar to falling under gravity?

Where did Wilson state that the US would have to force access to markets with violence?

Integrating an absolute function using Mathematica

Employer demanding to see degree after poor code review

Is there a public standard for 8 and 10 character grid locators?

Python program to convert a 24 hour format to 12 hour format

How does an ARM MCU run faster than the external crystal?

At what point in European history could a government build a printing press given a basic description?



How to Fix Syntax error in UPDATE statement


Nested With Statement CrashesSyntax error in INSERT INTO Statement in vb.neterror database: Syntax error in INSERT INTO statementcommand error *incorrect syntax near ','*How to fix position of scroll bar to bottom in DataGridView?Error on UPDATE statement when savingVB 2010 error (INSERT INTO) syntax errorsyntax error in UPDATE statement vb.net/ MS access 2007Vb net update statement issuehow to use group by in select statement in vb.net






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've been making a database for some payments and my code seems to have an error and I can't see where the problem is. I keep getting the "Syntax error in UPDATE statement" error in OleDbExecution was unhandled. Can someone help?



Here is my code:



Dim cnnOLEDB As New OleDbConnection

Dim cmdUpdate As New OleDbCommand

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|UBSOMSPayments.accdb")

If TextBox1.Text <> "" Then
cmdUpdate.CommandText = "UPDATE Payments SET Position='" & TextBox2.Text & "'," & "PaymentRecipient='" & TextBox3.Text & "'," & "PaymentFor='" & TextBox4.Text & "'," & "Amount='" & TextBox5.Text & "'," & "PayedAmount='" & TextBox6.Text & "'" & " WHERE AssignedOfficer = " & Val(TextBox1.Text)
'1MsgBox(cmdUpdate.CommandText)
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.Connection = conn
conn.Open()
cmdUpdate.ExecuteNonQuery() <--- Line where the error shows
conn.Close()
MsgBox("Record has been updated.")
Else
MsgBox("try again")
End If
cmdUpdate.Dispose()









share|improve this question






























    0















    I've been making a database for some payments and my code seems to have an error and I can't see where the problem is. I keep getting the "Syntax error in UPDATE statement" error in OleDbExecution was unhandled. Can someone help?



    Here is my code:



    Dim cnnOLEDB As New OleDbConnection

    Dim cmdUpdate As New OleDbCommand

    Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|UBSOMSPayments.accdb")

    If TextBox1.Text <> "" Then
    cmdUpdate.CommandText = "UPDATE Payments SET Position='" & TextBox2.Text & "'," & "PaymentRecipient='" & TextBox3.Text & "'," & "PaymentFor='" & TextBox4.Text & "'," & "Amount='" & TextBox5.Text & "'," & "PayedAmount='" & TextBox6.Text & "'" & " WHERE AssignedOfficer = " & Val(TextBox1.Text)
    '1MsgBox(cmdUpdate.CommandText)
    cmdUpdate.CommandType = CommandType.Text
    cmdUpdate.Connection = conn
    conn.Open()
    cmdUpdate.ExecuteNonQuery() <--- Line where the error shows
    conn.Close()
    MsgBox("Record has been updated.")
    Else
    MsgBox("try again")
    End If
    cmdUpdate.Dispose()









    share|improve this question


























      0












      0








      0








      I've been making a database for some payments and my code seems to have an error and I can't see where the problem is. I keep getting the "Syntax error in UPDATE statement" error in OleDbExecution was unhandled. Can someone help?



      Here is my code:



      Dim cnnOLEDB As New OleDbConnection

      Dim cmdUpdate As New OleDbCommand

      Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|UBSOMSPayments.accdb")

      If TextBox1.Text <> "" Then
      cmdUpdate.CommandText = "UPDATE Payments SET Position='" & TextBox2.Text & "'," & "PaymentRecipient='" & TextBox3.Text & "'," & "PaymentFor='" & TextBox4.Text & "'," & "Amount='" & TextBox5.Text & "'," & "PayedAmount='" & TextBox6.Text & "'" & " WHERE AssignedOfficer = " & Val(TextBox1.Text)
      '1MsgBox(cmdUpdate.CommandText)
      cmdUpdate.CommandType = CommandType.Text
      cmdUpdate.Connection = conn
      conn.Open()
      cmdUpdate.ExecuteNonQuery() <--- Line where the error shows
      conn.Close()
      MsgBox("Record has been updated.")
      Else
      MsgBox("try again")
      End If
      cmdUpdate.Dispose()









      share|improve this question
















      I've been making a database for some payments and my code seems to have an error and I can't see where the problem is. I keep getting the "Syntax error in UPDATE statement" error in OleDbExecution was unhandled. Can someone help?



      Here is my code:



      Dim cnnOLEDB As New OleDbConnection

      Dim cmdUpdate As New OleDbCommand

      Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|UBSOMSPayments.accdb")

      If TextBox1.Text <> "" Then
      cmdUpdate.CommandText = "UPDATE Payments SET Position='" & TextBox2.Text & "'," & "PaymentRecipient='" & TextBox3.Text & "'," & "PaymentFor='" & TextBox4.Text & "'," & "Amount='" & TextBox5.Text & "'," & "PayedAmount='" & TextBox6.Text & "'" & " WHERE AssignedOfficer = " & Val(TextBox1.Text)
      '1MsgBox(cmdUpdate.CommandText)
      cmdUpdate.CommandType = CommandType.Text
      cmdUpdate.Connection = conn
      conn.Open()
      cmdUpdate.ExecuteNonQuery() <--- Line where the error shows
      conn.Close()
      MsgBox("Record has been updated.")
      Else
      MsgBox("try again")
      End If
      cmdUpdate.Dispose()






      vb.net-2010






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 7:26









      Satish Saini

      1,80921529




      1,80921529










      asked Mar 24 at 7:12









      Erick Erick

      13




      13






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You should never use string concatenation to build SQL commands, but always a parameterized query to avoid SQL Injections.



          Try this:



          Change your query to something like this:



          "UPDATE [Payments] SET [Position] = ?, [PaymentRecipient] = ?, [PaymentFor] = ?, " & _
          "[Amount] = ?, [PayedAmount] = ? & _
          " WHERE [AssignedOfficer] = ?"


          and then add parameters:



          cmdUpdate.Parameters.AddWithValue("@p1", TextBox2.Text)
          cmdUpdate.Parameters.AddWithValue("@p2", TextBox3.Text)
          cmdUpdate.Parameters.AddWithValue("@p3", TextBox4.Text)
          cmdUpdate.Parameters.AddWithValue("@p4", TextBox5.Text)
          cmdUpdate.Parameters.AddWithValue("@p5", TextBox6.Text)
          cmdUpdate.Parameters.AddWithValue("@p6", TextBox1.Text)
          cmdUpdate.ExecuteNonQuery()





          share|improve this answer

























          • is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

            – Erick
            Mar 24 at 8:49











          • @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

            – Satish Saini
            Mar 24 at 14:52











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321507%2fhow-to-fix-syntax-error-in-update-statement%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You should never use string concatenation to build SQL commands, but always a parameterized query to avoid SQL Injections.



          Try this:



          Change your query to something like this:



          "UPDATE [Payments] SET [Position] = ?, [PaymentRecipient] = ?, [PaymentFor] = ?, " & _
          "[Amount] = ?, [PayedAmount] = ? & _
          " WHERE [AssignedOfficer] = ?"


          and then add parameters:



          cmdUpdate.Parameters.AddWithValue("@p1", TextBox2.Text)
          cmdUpdate.Parameters.AddWithValue("@p2", TextBox3.Text)
          cmdUpdate.Parameters.AddWithValue("@p3", TextBox4.Text)
          cmdUpdate.Parameters.AddWithValue("@p4", TextBox5.Text)
          cmdUpdate.Parameters.AddWithValue("@p5", TextBox6.Text)
          cmdUpdate.Parameters.AddWithValue("@p6", TextBox1.Text)
          cmdUpdate.ExecuteNonQuery()





          share|improve this answer

























          • is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

            – Erick
            Mar 24 at 8:49











          • @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

            – Satish Saini
            Mar 24 at 14:52















          0














          You should never use string concatenation to build SQL commands, but always a parameterized query to avoid SQL Injections.



          Try this:



          Change your query to something like this:



          "UPDATE [Payments] SET [Position] = ?, [PaymentRecipient] = ?, [PaymentFor] = ?, " & _
          "[Amount] = ?, [PayedAmount] = ? & _
          " WHERE [AssignedOfficer] = ?"


          and then add parameters:



          cmdUpdate.Parameters.AddWithValue("@p1", TextBox2.Text)
          cmdUpdate.Parameters.AddWithValue("@p2", TextBox3.Text)
          cmdUpdate.Parameters.AddWithValue("@p3", TextBox4.Text)
          cmdUpdate.Parameters.AddWithValue("@p4", TextBox5.Text)
          cmdUpdate.Parameters.AddWithValue("@p5", TextBox6.Text)
          cmdUpdate.Parameters.AddWithValue("@p6", TextBox1.Text)
          cmdUpdate.ExecuteNonQuery()





          share|improve this answer

























          • is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

            – Erick
            Mar 24 at 8:49











          • @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

            – Satish Saini
            Mar 24 at 14:52













          0












          0








          0







          You should never use string concatenation to build SQL commands, but always a parameterized query to avoid SQL Injections.



          Try this:



          Change your query to something like this:



          "UPDATE [Payments] SET [Position] = ?, [PaymentRecipient] = ?, [PaymentFor] = ?, " & _
          "[Amount] = ?, [PayedAmount] = ? & _
          " WHERE [AssignedOfficer] = ?"


          and then add parameters:



          cmdUpdate.Parameters.AddWithValue("@p1", TextBox2.Text)
          cmdUpdate.Parameters.AddWithValue("@p2", TextBox3.Text)
          cmdUpdate.Parameters.AddWithValue("@p3", TextBox4.Text)
          cmdUpdate.Parameters.AddWithValue("@p4", TextBox5.Text)
          cmdUpdate.Parameters.AddWithValue("@p5", TextBox6.Text)
          cmdUpdate.Parameters.AddWithValue("@p6", TextBox1.Text)
          cmdUpdate.ExecuteNonQuery()





          share|improve this answer















          You should never use string concatenation to build SQL commands, but always a parameterized query to avoid SQL Injections.



          Try this:



          Change your query to something like this:



          "UPDATE [Payments] SET [Position] = ?, [PaymentRecipient] = ?, [PaymentFor] = ?, " & _
          "[Amount] = ?, [PayedAmount] = ? & _
          " WHERE [AssignedOfficer] = ?"


          and then add parameters:



          cmdUpdate.Parameters.AddWithValue("@p1", TextBox2.Text)
          cmdUpdate.Parameters.AddWithValue("@p2", TextBox3.Text)
          cmdUpdate.Parameters.AddWithValue("@p3", TextBox4.Text)
          cmdUpdate.Parameters.AddWithValue("@p4", TextBox5.Text)
          cmdUpdate.Parameters.AddWithValue("@p5", TextBox6.Text)
          cmdUpdate.Parameters.AddWithValue("@p6", TextBox1.Text)
          cmdUpdate.ExecuteNonQuery()






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 24 at 14:51

























          answered Mar 24 at 7:42









          Satish SainiSatish Saini

          1,80921529




          1,80921529












          • is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

            – Erick
            Mar 24 at 8:49











          • @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

            – Satish Saini
            Mar 24 at 14:52

















          • is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

            – Erick
            Mar 24 at 8:49











          • @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

            – Satish Saini
            Mar 24 at 14:52
















          is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

          – Erick
          Mar 24 at 8:49





          is there a difference if I'm using access database? Anyway the same error still pops up. I have my table name and fields correctly spelled here if you might say that's the reason.

          – Erick
          Mar 24 at 8:49













          @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

          – Satish Saini
          Mar 24 at 14:52





          @Erick I have updated my answer. Try to escape the columns with the updated query and let me know if that works.

          – Satish Saini
          Mar 24 at 14:52



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321507%2fhow-to-fix-syntax-error-in-update-statement%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript