Click here to Skip to main content
15,849,406 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want to show user Id of current Transaction in a small Sale System that i need to get max of My Identity Id During My program now i want to know that i can get it when table is empty ???? for example: Id seed is 1000 marshal.tbl_Transaction.max(l=>l.Id)+1; is it work true when my table is empty at first of program?????????? thanks

1 solution


This is really incorrect approach. You should not use Max value of ID column for Next Identity value.

Problem with your approach : At the same time two User open the same page to add New value. And both of them will assign with same ID value. Data will be inconsistent.

Correct approach : When user open this form, you need to add one entry in the database. You need to add one more column with IsValidData field. It should be false until user click the save button. You need IsValidData field because user may come to that form and close without saving. In this scenario you have one invalid entry in database. You need to clear such entry from the database with particular time interval. Although this process become more complicated but if you need Identity value to be display, You need to go for such complex process.

Let's see if other CP Experts come with more feasible solution.

-Amit Gajjar
Share this answer
daghune 5-Sep-12 1:10am    
thank you
AmitGajjar 5-Sep-12 1:11am    
Your Welcome.
daghune 5-Sep-12 1:19am    
If we load Transaction by first row that its ISValidData is false,In a situation that a user open that form for add data to table and until he click on save button , another user open that form ,now two user Simultaneously are putting differ data in a single row????????
AmitGajjar 5-Sep-12 1:32am    
No for each opening of page you need to add one Invalid Row in database. You also need to add column with DataOfCreation. After 24hrs you can execute one batch file to clear 24 hrs older Invalidated rows. So your answer is, if two user open this page. Two invalid rows will be created.
Prasad_Kulkarni 13-Sep-12 5:57am    
Good one +5

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