Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello all

i have a table named as "tblDBUser"
that having fields

intDBUserId,strLogin,strName,strPassword,intDBRoleType

in which i want that intDBUserId should be incremented automatically when i enter the records,

i write a query which is as followa...........................




SQL
INSERT INTO tblDBUser (intDBUserId,strLogin,strName,strPassword,intDBRoleType)
values((select MAX(intDBUserId)+1 from tblDBUser
 ,strLogin,strName,strPassword,intDBRoleType));



the problem is it is shows the error

"number of query values is not same the destination fields" can u please help me out where i made a mistake



thanks and regards
subiya
Posted
Comments
Prerak Patel 15-Apr-11 5:44am    
Get your answer here: http://www.codeproject.com/Questions/181987/how-to-generate-auto-number-in-msaccess.aspx

Don't repost your question. You can modify the question if you wish.

Select datatype for that column to AutoNumber.
 
Share this answer
 
REPOST: how to generate auto number in msaccess[^]

First of all I would say, use AutoNumber datatype for your ID field.

For this question, you had closed it wrong.
INSERT INTO tblDBUser (intDBUserId,                                strLogin,strName,strPassword,intDBRoleType)
                values((select MAX(intDBUserId)+1 from tblDBUser), strLogin,strName,strPassword,intDBRoleType);



If you use AutoNumber, you have to use following only. intDBUserId will automatically be generated.
INSERT INTO tblDBUser (strLogin,strName,strPassword,intDBRoleType)
                values(strLogin,strName,strPassword,intDBRoleType);
 
Share this answer
 
v2
Comments
ahsan.subiya 15-Apr-11 6:13am    
code still not working sir,
i dont want to use the autonumber.
Prerak Patel 15-Apr-11 6:18am    
Why not? What is the problem with that?
ahsan.subiya 15-Apr-11 6:21am    
sir it display error
which is not define
Prerak Patel 15-Apr-11 6:24am    
If you use AutoNumber, you have to use following only. intDBUserId will automatically be generated.

INSERT INTO tblDBUser (strLogin,strName,strPassword,intDBRoleType)
values(strLogin,strName,strPassword,intDBRoleType);
ahsan.subiya 15-Apr-11 6:28am    
thats i know bt my senior is not allowing me to use that

can you give me another code for the same thing please

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