Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
cmd1.CommandText = "INSERT INTO LoginTable(ID,GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)";

//all the specified field had no problem
//ID is an autonumber column

//error:syntax error
Posted
Updated 16-Sep-13 2:51am
v2

Replace:
SQL
INSERT INTO LoginTable(ID,GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)

with:
SQL
INSERT INTO LoginTable(GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)


Note: You should omit auto-increment field in INSERT statement.


For further information, please see:
Fields that generate numbers automatically in Access[^]
How to reset an AutoNumber field value in Access[^]
 
Share this answer
 
Comments
Thanks7872 16-Sep-13 12:28pm    
+5
Maciej Los 16-Sep-13 12:52pm    
Thank you ;)
Well this is very simple task
if you have watched it carefully see your query you have 6 tables values and 5 parameters so it is always gives you error all the tabled values which you want to insert then must be matched with the parameters suppose you want to insert 3 fields then you can add 3 parameters only

now take a look at your query you have id as a extra field as you mentioned that you have id as a auto increament so just remove that one

and your new query will look like this one

SQL
cmd1.CommandText = "INSERT INTO LoginTable(GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)";



:)
 
Share this answer
 
You can have a look at this examples given at the below link:
syntax-error-on-insert-into-single-column-auto-increment-table[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900