Stumped - what is wrong with this insert statement?

PatM

Well-known member
Joined
Dec 5, 2012
Messages
52
Programming Experience
10+
VB.NET:
INSERT INTO users (fullname,username,password,role) VALUES ('Sean Guy','sguy','password',2)
Seems pretty simple. I tried the "2" with single quotes as well with no luck. I even checked letter case to make sure everything matches
 
Solution
"Password" is a reserved word in Jet/ACE SQL, so you must escape it when using it as an identifier. You do that by wrapping it in brackets, just as you do in VB.
"Password" is a reserved word in Jet/ACE SQL, so you must escape it when using it as an identifier. You do that by wrapping it in brackets, just as you do in VB.
 
Solution
I had no clue that was a problem. Access 2003 let me name the column that without complaint too.

Oh well, now to figure out how to parameterize the same same insert.

Salamat po!
 
You can name tables and columns whatever you want. It's only in SQL code that it becomes a problem, because reserved words, spaces and other special characters will cause syntax errors if not escaped. It is better to avoid such names altogether. Given that passwords should be hashed in real systems, such columns can be named PasswordHash and there's no issue.
 
Back
Top