2 Replies - 3170 Views - Last Post: 05 December 2010 - 07:42 PM Rate Topic: -----

#1 Guest_Kathy*


Reputation:

Database error Syntax error in INSERT INTO statement.

Posted 05 December 2010 - 04:07 PM

I am trying to execute a command that inserts a row but I keep getting the error "Database error Syntax error in INSERT INTO statement." What am I doing incorrectly? I know for Ole Db refers to the parameters by sequence and I've done in the correct sequence. I left out the ID since it is auto generated could that be causing a problem?

  
 Sub RobotMovement()
        Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Robot.accdb;"
        Dim connection As New OleDbConnection()
        connection.ConnectionString = connectionString

        Dim insertStatement As String = "INSERT RobotMovement(Direction, [TimeStamp], X, Y,)VALUES(mDirection, TimeOfDay, Form1.lblArrow.Location.X, Form1.lblArrow.Location.Y,)"

        Dim insertCommand As New OleDbCommand(insertStatement, connection)
        insertCommand.Parameters.AddWithValue("Direction", mDirection)
        insertCommand.Parameters.AddWithValue("[TimeStamp]", TimeOfDay)
        insertCommand.Parameters.AddWithValue("X", lblArrow.Location.X)
        insertCommand.Parameters.AddWithValue("Y", lblArrow.Location.Y)

        Try
            connection.Open()
            insertCommand.ExecuteNonQuery()
        Catch ex As OleDbException
            MessageBox.Show("Database error " & ex.Message, ex.GetType.ToString)
        Finally
            connection.Close()
        End Try



Is This A Good Question/Topic? 0

Replies To: Database error Syntax error in INSERT INTO statement.

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Re: Database error Syntax error in INSERT INTO statement.

Posted 05 December 2010 - 06:26 PM

Moved to VB.NET Help. Please reserve the VB.NET Programmers section for topical, non-help related discussion.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: Database error Syntax error in INSERT INTO statement.

Posted 05 December 2010 - 07:42 PM

Read up on your 'insert' commands. I believe you are missing the "INTO" keyword.

http://msdn.microsof...y/dd776381.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1