Resolved Syntax error in INSERT INTO statement

KenQui

Member
Joined
May 11, 2022
Messages
12
Programming Experience
Beginner
What is wrong in my code below?
How to fix the error?


Private Sub AddAdmin()

' ADD PARAMETERS
aAccess.AddParam("@admin_no", txtANo.Text)
aAccess.AddParam("@username", txtAUsername.Text)
aAccess.AddParam("@password", txtAPassword.Text)


' EXECUTE INSERT COMMAND
aAccess.ExecQuery("INSERT INTO db_admin (Admin_No,Username,Password) " & _
"VALUES (@admin_no,@username,@password); ")

' REPORT & ABORT ON ERRORS
If Not String.IsNullOrEmpty(aAccess.Exception) Then MsgBox(aAccess.Exception) : Exit Sub

' SUCCESS!!
MsgBox("The book was added successfully")


Me.RefreshGrid()

End Sub
 
Solution
I'm not sure whether you have marked this thread Resolved by mistake, given that you haven't actually provided the solution. If you resolve your own issue, please post the solution. It might help someone else and we might even be able to suggest an improvement.

In this case, the issue is that "Password" is a reserved word in Jet/ACE SQL and so you cannot use it as an identifier without escaping it. Just as in VB, you escape an identifier in Jet/ACE SQL by enclosing it in brackets.
I'm not sure whether you have marked this thread Resolved by mistake, given that you haven't actually provided the solution. If you resolve your own issue, please post the solution. It might help someone else and we might even be able to suggest an improvement.

In this case, the issue is that "Password" is a reserved word in Jet/ACE SQL and so you cannot use it as an identifier without escaping it. Just as in VB, you escape an identifier in Jet/ACE SQL by enclosing it in brackets.
 
Solution
Im sorry about that, but yeah your right. i put bracket in password and it work. Thank you so much for the info.
 
Back
Top