Click here to Skip to main content
15,913,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys,I m working with WinForms and Database,The forms is about selling items.I want to store each sale with unique number(Bill_no).My idea about bill number is "ddmmyyy0000" 0000 will reset everyday.Can you please help me how can i do this? i also want to show bill number at time of transaction in textbox?
if you have suggestion about bill you are wellcome.

What I have tried:

So far i m getting incremental values from database and and manipulating it Sale Form for next value.But this method is very is very inefficient and disorganized.
Posted
Updated 3-Nov-18 2:53am

1 solution

Why? Just use an IDENTITY field (which will autoincrement) and a DATE or DATETIME2 column to store the date - it's a lot more flexible, a lot easier to maintain, and fits better with legal and accounting procedure, neither of which thinks it is a good idea to have "broken sequences" because it's possible to add or remove items / invoices at a later date.

If you really need the date and the daily sequence number, then:
1) Don't do it ddmmyy: make it yyMMdd (or better yyyyMMdd) as they sort better.
2) Use a computed column to generate it from the two other columns (You can get "that day" items easily with a WHERE clause, and the sequence number with the ROW_NUMBER function for the date. Then JOIN that back to your original table.
 
Share this answer
 
Comments
Danish Kareem 3-Nov-18 10:21am    
I m using Identity field as a bill number right now.is it good way to track invoices but i wanted to rest sequence everyday.

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