Click here to Skip to main content
15,918,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,

I have a database with auto number type key, I would like to insert data by data command.
I would like to insert data into table from VB.NET form without inserting Primary key Field,

What I mean is I would like to insert all fields except primary key.
I would like the primary key to take value automatic, but when I try it, I see an error.
Posted
Updated 13-Nov-11 3:44am
v2
Comments
André Kraak 13-Nov-11 9:45am    
Please specify the error message you are getting.

If you wish to change your question use the Improve Question button.
synctor 13-Nov-11 13:00pm    
Error msg : your query insert value and destination is not same
mr. Andre can i have your Email or messenger ID ? :)
Amir Mahfoozi 13-Nov-11 12:08pm    
If you are sure that you have specified autonumber field correctly, it's not necessary to insert the autonumber field in insertion. So most likely the error is related to another thing :-?

1 solution

Agree with Amir.
The right error message is Number of query values and destination fields are not the same[^]

Don't include the AutoNumber column in your query.

Wrong
SQL
INSERT INTO EMP(AutoNo, Name, Age, Phone) VALUES(1,'Employee1','25','435435345')

INSERT INTO EMP(AutoNo, Name, Age, Phone) VALUES('Employee1','25','435435345')--You query must be like this one

Right
SQL
INSERT INTO EMP(Name, Age, Phone) VALUES('Employee1','25','435435345')
 
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