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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현