Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi I have a database.sdf attached to my data entry form, when I input data in the datagridview, I would like the userid to auto generate in ascending order
Orcun Iyigun 27-Feb-13 3:37am    
Before binding your datagridview sort your source by userid and after that bind your source to gridview.
CHill60 27-Feb-13 4:40am    
If your database is T-SQL compatible (SQL Server, MySQL etc) then you can have a column set up to automatically generate an ID using IDENTITY(1,1). Come to think of it I'm fairly sure there is something similar in Access and SQL Server compact too
Sergey Alexandrovich Kryukov 5-Mar-13 14:10pm    
Again, not a question. Please understand, this is a Questions & Answers forum.

Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.


In your database schema have one column set up to use the IDENTITY property
create table myTable(
ID int not null IDENTITY(1,1)
-- other columns ...

This will automatically create an ID starting at 1 (1,1) and incrementing by 1 each time a row is added (1,1). It will automatically handle any rows that are deleted from the table ensuring that the ID is always unique.

See this link[^] for the documentation
Share this answer
boogac 27-Feb-13 4:51am    
JayantaChatterjee 5-Mar-13 22:15pm    
My 5.
user the same as given in Solution 1 .

but you can do it my query .

just execute an select query b4 the insert query

SELECT COUNT(username)+1 AS 'NewId' FROM xyzTabel

And now user NewId as and Newidfor your new user
Share this answer
Mycroft Holmes 5-Mar-13 20:29pm    
This solution is only valid on a single user database.

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