2

This query runs perfectly in Access 2007 but when I try to execute it in my code I get Syntax error in INSERT INTO statement. Someone please help.

Dim sql1 As String
sql1 = "INSERT INTO CustomerDtl (KioskID, ClientID, Language, SalesType) VALUES ('AD903',1,'English','Wholesale')"
ObjAccess.ExecuteQuery(sql1)

And this is the ExecuteReader function:

Public Function ExecuteQuery(ByVal SQLQuery As String)

        'This Function Executes SQL Statement against connection and returns number of rows affected'

        dbCommand = New OleDbCommand
        Call OpenConnection()

        With dbCommand
            .Connection = dbConnection
            .CommandType = CommandType.Text
            .CommandText = SQLQuery
            .ExecuteNonQuery()
            .Dispose()
        End With

        Call CloseConnection()

End Function

1 Answer 1

2

Langauge is a reserved keyword. escape it by wrapping [ ].

sql1 = "INSERT INTO CustomerDtl (..., [Language], ....) VALUES(...)"
Sign up to request clarification or add additional context in comments.

1 Comment

consider also using parameters to avoid injection. mikesdotnetting.com/Article/26/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.