Results 1 to 10 of 10

Thread: [RESOLVED] SQL help! What am i doing wrong?

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved [RESOLVED] SQL help! What am i doing wrong?

    Hi all,

    The following code

    Code:
        Function AddToDatabase(ByVal TAG As String, ByVal EquipmentType As String, ByVal Description As String, ByVal Status1 As String, ByVal Status2 As String, ByVal DateChanged As Date, ByVal Comments As String, ByVal UserID As String) As Boolean
            'Write to the Database
            Try
                Dim connectionSQL As New OleDbConnection(strSQLconn & DataSourcePath)
                Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID", connectionSQL)
                connectionSQL.Open()
                MsgBox(connectionSQL.State.ToString)
    
                With command.Parameters
                    .AddWithValue("@EquipmentType", EquipmentType)
                    .AddWithValue("@TAG", TAG)
                    .AddWithValue("@Descriptor", Description)
                    .AddWithValue("@Status1", Status1)
                    .AddWithValue("@Status2", Status2)
                    .AddWithValue("@DateChanged", "01/01/2010")
                    .AddWithValue("@Comments", Comments)
                    .AddWithValue("@Userid", UserID)
                End With
                command.ExecuteNonQuery()
                'command.Dispose()
                'Need to reset the form for the next one
                Return True
            Catch ex As Exception
                MsgBox(ex.ToString)
                Clipboard.SetText(ex.ToString)
    
                Return False
            End Try
        End Function
    Generates this error

    Code:
    System.Data.OleDb.OleDbException was caught
      ErrorCode=-2147217900
      Message="Syntax error in INSERT INTO statement."
      Source="Microsoft JET Database Engine"
      StackTrace:
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
           at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
           at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
           at Tool.clsSQL.AddToDatabase(String TAG, String EquipmentType, String Description, String Status1, String Status2, DateTime DateChanged, String Comments, String UserID) in C:\Documents and Settings\dinoken\My Documents\Visual Studio 2005\Projects\Tool\clsSQL.vb:line 37
    Any ideas folks?
    If you find my thread helpful, please remember to rate me

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: SQL help! What am i doing wrong?

    You forgot the closing bracket at the end of the SQL string (your parameter list).

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: SQL help! What am i doing wrong?

    What database are you using?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: SQL help! What am i doing wrong?

    As ForumAccount stated, you are missing the closing parenthesis in your Command string:

    vb Code:
    1. Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID)", connectionSQL)

  5. #5
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: SQL help! What am i doing wrong?

    Quote Originally Posted by stateofidleness View Post
    As ForumAccount stated, you are missing the closing parenthesis in your Command string:

    vb Code:
    1. Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID", connectionSQL))
    Wrong place, it's after @UserID that he is missing it.

  6. #6

  7. #7
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: SQL help! What am i doing wrong?

    "And that's a magic numberrrr?"

    You're not going to like this but its still wrong

    Code:
    Dim command As New OleDbCommand("INSERT INTO PMTStatus (EquipmentType, TAG, Descriptor, Status1, Status2, DateChanged, Comments, UserID) VALUES (@EquipmentType, @TAG, @Descriptor, @Status1, @Status2, @DateChanged, @Comments, @UserID)", connectionSQL)

  8. #8

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: SQL help! What am i doing wrong?

    The problem could also be the use of database reserved words for column names... For example, "descriptor" is a reserved word in DB2, ODBC, PostgreSQL 8 and some other DB's. That's why besides the obvious syntax error, you also need to check the field names.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  10. #10

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: SQL help! What am i doing wrong?

    Ahhh all resolved guys!

    Thanks, it was the )
    If you find my thread helpful, please remember to rate me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width