Click here to Skip to main content
15,890,932 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear All
I am trying to create a project like billing software. in this form i have a text box for bill no. and now i want to +1 every time of last bill no.

i am tring a lot but at run time it is not refreshing every time



please help me ...................
Posted
Updated 29-Jan-12 23:20pm
v2
Comments
CRDave1988 30-Jan-12 5:14am    
can you show your code?
Rajesh Anuhya 30-Jan-12 5:21am    
Post your code what you tried.

The easiest way is to create the bill number field as an Identity field: that way SQL Server will take care of it for you. You then don't specifiy the field content, SQL server will assign it a new, incremented value when you use the INSERT command.
To do that:

In SQL server Management Studio, create your table.
Create the BillNo field, as an int.
In the Properties, expand "Identity Specification".
Change "(Is Identity)" to "Yes"

Done!
 
Share this answer
 
Hi Use OriginalGriff answer after that set identity seed to 1. it will solve your problem.
 
Share this answer
 
If you are using a database table for the bill number, just set bill no to an identity column and then get the last bill number using @@identity(here[^]) and then add one to it.
 
Share this answer
 
Comments
Dave Kreskowiak 30-Jan-12 10:31am    
And if two clients run this at the exact same time?? You now have two client that are trying to use the same id number. You NEVER manually add an increment to an identity field to generate a new identity for this reason.
Abhinav S 30-Jan-12 10:51am    
Worse case one insert will fail?
hello,

You can do this in two ways :
1. either set a auto-generated column in database table. because when you submit then each time it will insert unique number.
2. or get a integer field and when you submit that bill detail then first execute query to get max. bill no. and add 1 in that no. and then execute with details.

Hope this will help you.
And you can ask for more details. And don't forget to mark as answer if it helps. :)
 
Share this answer
 
Comments
Dave Kreskowiak 30-Jan-12 10:33am    
Your second option sucks because if you have two clients running this code at nearly the same time, you get the same ID number being generated on two machines.

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