Click here to Skip to main content
15,915,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I need a help

Doid I am getting by counting number of records in database.
My requirement is if it is a new year the count must start again from 1

Example(2011)

2011scl001-D0
2011scl002-DO
2011scl003_Do

(2012)
VB
2012scl001-D0
        2012scl002-DO
        2012scl003_Do


Could u pls advice

if (count < 10)
            {
                if (month == 1)
                {
                    DoId = (DateTime.Now.Year + cusId + ("00") + (count + 1) + "-DO").ToString();

                }
                else 
                {
                    DoId = (DateTime.Now.Year + cusId + ("00") + (count + 1) + "-DO").ToString();

                }
                }


Thanks
Posted

1 solution

I would just reset count to 1 in the if clause.
C#
if (month == 1)
               {
                   count=1;
                   DoId = (DateTime.Now.Year + cusId + ("00") + (count + 1) + "-DO").ToString();

               }
               else
               {
                   DoId = (DateTime.Now.Year + cusId + ("00") + (count + 1) + "-DO").ToString();

               }
 
Share this answer
 
Comments
Aniket Yadav 12-Feb-12 0:21am    
Hello Abhinav,

Your solution is okay but there is one flaw in it.

If I set the count to 1 then for the 1st month, my DoId will be 2012scl002-DO. And if it continues then for the 12th Month the DoId will be 2012scl0013-DO
Abhinav S 12-Feb-12 1:40am    
Try by setting count=0 instead of 1.
Lancy.net 12-Feb-12 1:30am    
sorry may be my question is not clear
what i need is count value should reset every year...
for example if i have 10 dos in jan starts with 2012scl001-Do--2012scl010-Do
feb one 2012scl011.........
2013 jan first do must 2013scl001

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