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. Visual Basic
  4. Syntax error in INSERT INTO statement.

Syntax error in INSERT INTO statement.

Scheduled Pinned Locked Moved Visual Basic
helpdesigndata-structuresdebugging
12 Posts 3 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.
  • M Offline
    M Offline
    Manik Nath
    wrote on last edited by
    #1

    hi there, Can someone help with this. Syntax error in INSERT INTO statement. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. Source Error: Line 84: strsqlinsert = "INSERT INTO Transmittal(Action, Copies, Drw_Doc_Num, Kind_Attn, Project_Name, Referenced_To, Rev_Num, Title, Username)" + "VALUES('" + TextBox9.Text + "', '" + TextBox7.Text + "', '" + TextBox6.Text + "', '" + TextBox4.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox8.Text + "', '" + TextBox5.Text + "', '" + TextBox1.Text + "' )" Line 85: TransDataAdapter.InsertCommand.CommandText = (strsqlinsert) Line 86: TransDataAdapter.InsertCommand.ExecuteNonQuery() Line 87: TransConnection.Close() Line 88: End Sub Source File: C:\Inetpub\wwwroot\OM\trans1.aspx.vb Line: 86 Stack Trace: [OleDbException (0x80040e14): Syntax error in INSERT INTO statement.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +154 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +54 OM.trans1.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\OM\trans1.aspx.vb:86 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1263

    R 1 Reply Last reply
    0
    • M Manik Nath

      hi there, Can someone help with this. Syntax error in INSERT INTO statement. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. Source Error: Line 84: strsqlinsert = "INSERT INTO Transmittal(Action, Copies, Drw_Doc_Num, Kind_Attn, Project_Name, Referenced_To, Rev_Num, Title, Username)" + "VALUES('" + TextBox9.Text + "', '" + TextBox7.Text + "', '" + TextBox6.Text + "', '" + TextBox4.Text + "', '" + TextBox2.Text + "', '" + TextBox3.Text + "', '" + TextBox8.Text + "', '" + TextBox5.Text + "', '" + TextBox1.Text + "' )" Line 85: TransDataAdapter.InsertCommand.CommandText = (strsqlinsert) Line 86: TransDataAdapter.InsertCommand.ExecuteNonQuery() Line 87: TransConnection.Close() Line 88: End Sub Source File: C:\Inetpub\wwwroot\OM\trans1.aspx.vb Line: 86 Stack Trace: [OleDbException (0x80040e14): Syntax error in INSERT INTO statement.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +154 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +54 OM.trans1.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\OM\trans1.aspx.vb:86 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1263

      R Offline
      R Offline
      Rizwan Bashir
      wrote on last edited by
      #2

      manik nath wrote: [OleDbException (0x80040e14): Syntax error in INSERT INTO statement.] insead of writing the long codes you can just work on insert statement. if you could post the value of strsqlinsert variable then we could suggest you some thing better and proper

      M 1 Reply Last reply
      0
      • R Rizwan Bashir

        manik nath wrote: [OleDbException (0x80040e14): Syntax error in INSERT INTO statement.] insead of writing the long codes you can just work on insert statement. if you could post the value of strsqlinsert variable then we could suggest you some thing better and proper

        M Offline
        M Offline
        Manik Nath
        wrote on last edited by
        #3

        well rizwan, here's the value of strsqlinsert strinsert = "INSERT INTO Transmittal(ReferencedTo, Title, NumberofCopies, Username, ProjectName, KindAttn, RevisionNumber, Action, DrawingDocumentNumber)" + "VALUES ('" + TextBox3.Text + "', '" + TextBox5.Text + "', '" + TextBox9.Text + "', '" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox4.Text + "', '" + TextBox10.Text + "', '" + TextBox11.Text + "', '" + TextBox7.Text + "' )" it doesn't come in one line here. help me if you could.

        D 1 Reply Last reply
        0
        • M Manik Nath

          well rizwan, here's the value of strsqlinsert strinsert = "INSERT INTO Transmittal(ReferencedTo, Title, NumberofCopies, Username, ProjectName, KindAttn, RevisionNumber, Action, DrawingDocumentNumber)" + "VALUES ('" + TextBox3.Text + "', '" + TextBox5.Text + "', '" + TextBox9.Text + "', '" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox4.Text + "', '" + TextBox10.Text + "', '" + TextBox11.Text + "', '" + TextBox7.Text + "' )" it doesn't come in one line here. help me if you could.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Two problems... The first is that you don't have a spcae just before the word "VALUES", so your SQL looks likes this:

          ...Action, DrawingDocumentNumber)VALUES ('...

          which I believe is a syntax error in SQL... Second, drop this string concatenation garbage and make your life much easier and convert this to parameterized queries. You'll automatically eliminate about 75% of the problems you get, like the one your facing now!, by using string concatenation... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Two problems... The first is that you don't have a spcae just before the word "VALUES", so your SQL looks likes this:

            ...Action, DrawingDocumentNumber)VALUES ('...

            which I believe is a syntax error in SQL... Second, drop this string concatenation garbage and make your life much easier and convert this to parameterized queries. You'll automatically eliminate about 75% of the problems you get, like the one your facing now!, by using string concatenation... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            M Offline
            M Offline
            Manik Nath
            wrote on last edited by
            #5

            hi dave, thanx for your sugesstion. but i did not eaxctly get you. could you just modify the string i sent and then give it you me.

            D 1 Reply Last reply
            0
            • M Manik Nath

              hi dave, thanx for your sugesstion. but i did not eaxctly get you. could you just modify the string i sent and then give it you me.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              strinsert = "INSERT INTO Transmittal(ReferencedTo, Title, NumberofCopies, Username, ProjectName, KindAttn, RevisionNumber, Action, DrawingDocumentNumber)" + **" VALUES ('"** + TextBox3.Text + "', '" + TextBox5.Text + "', '" + TextBox9.Text + "', '" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox4.Text + "', '" + TextBox10.Text + "', '" + TextBox11.Text + "', '" + TextBox7.Text + "' )" All you had to do is add a space before your "VALUES" keyword. This is one reason why you DO NOT USE string concatenation to build your SQL statements. How you're building your statement can be broken so easily, it's silly. All the user has to do is put a ' character in any one of those text boxes and your code breaks. Learn how to do it the correct way now, before this bad habit becomes your normal method. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              M 1 Reply Last reply
              0
              • D Dave Kreskowiak

                strinsert = "INSERT INTO Transmittal(ReferencedTo, Title, NumberofCopies, Username, ProjectName, KindAttn, RevisionNumber, Action, DrawingDocumentNumber)" + **" VALUES ('"** + TextBox3.Text + "', '" + TextBox5.Text + "', '" + TextBox9.Text + "', '" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + TextBox4.Text + "', '" + TextBox10.Text + "', '" + TextBox11.Text + "', '" + TextBox7.Text + "' )" All you had to do is add a space before your "VALUES" keyword. This is one reason why you DO NOT USE string concatenation to build your SQL statements. How you're building your statement can be broken so easily, it's silly. All the user has to do is put a ' character in any one of those text boxes and your code breaks. Learn how to do it the correct way now, before this bad habit becomes your normal method. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                M Offline
                M Offline
                Manik Nath
                wrote on last edited by
                #7

                thanx dave, the problem is solved by ur code. but the this method is working fine on one application. but on another it again gives the same syntax error. what to do?:( also what do you mean by parametrised query. or what is the better method can you tell me.

                D 1 Reply Last reply
                0
                • M Manik Nath

                  thanx dave, the problem is solved by ur code. but the this method is working fine on one application. but on another it again gives the same syntax error. what to do?:( also what do you mean by parametrised query. or what is the better method can you tell me.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  The syntax error is coming up because you miss-paired double quote marks somewhere. You can get a taste of parameterized queries here[^]. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  M 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    The syntax error is coming up because you miss-paired double quote marks somewhere. You can get a taste of parameterized queries here[^]. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                    M Offline
                    M Offline
                    Manik Nath
                    wrote on last edited by
                    #9

                    but dave if that is the case then it should give error in both the cases. in one form the syntax is working fine and in another form it's giving error. i have also double checked everything.

                    D 1 Reply Last reply
                    0
                    • M Manik Nath

                      but dave if that is the case then it should give error in both the cases. in one form the syntax is working fine and in another form it's giving error. i have also double checked everything.

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      All I can say is you're doing something wrong. If you're using the EXACT same statement in both forms, you've missed a character somewhere. Think about it! If the statement works on one form, it must work. So what's different about it on the second form? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                      M 1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        All I can say is you're doing something wrong. If you're using the EXACT same statement in both forms, you've missed a character somewhere. Think about it! If the statement works on one form, it must work. So what's different about it on the second form? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                        M Offline
                        M Offline
                        Manik Nath
                        wrote on last edited by
                        #11

                        ii checked everything dave twice and thrice. but the webform on which the code doesn't work and gives the error. also doesn't work with a code as simple as this. strsqlinsert = "INSERT INTO Chec (first)" + " VALUES (" + TextBox1.Text + ")" if there is something wrong with it i don't know about it.

                        D 1 Reply Last reply
                        0
                        • M Manik Nath

                          ii checked everything dave twice and thrice. but the webform on which the code doesn't work and gives the error. also doesn't work with a code as simple as this. strsqlinsert = "INSERT INTO Chec (first)" + " VALUES (" + TextBox1.Text + ")" if there is something wrong with it i don't know about it.

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #12

                          If your getting a "syntax error", you might want to consider what the field "first" is defined as and what is in the textbox.Text. If your trying to put a string into a number field, obviously, it's not going to work. Seriously, pick up a book on SQL and VB.NET and save yourself the aggravation. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                          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