Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
I need help with generating autonumbers for filling in data on the form.

I have 10 textboxes and one button, when I write in data in each of those textboxes and click button then all those data have been added to binded table. but one excluded textbox is for generating autonumbers or I wanna it to be that way
the form for making these autonumbers should be like this

current year_number

example
2011_13
2011_14
.......
Posted

How come it can be a problem? You know the year, month, etc. from System.DateTime.Now.

See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA
 
Share this answer
 
Comments
Programm3r 16-May-11 9:09am    
I agree, you can make use of System.DateTime....
Sergey Alexandrovich Kryukov 16-May-11 12:28pm    
I would say, OP just have to...
--SA
yesotaso 16-May-11 15:38pm    
...write a COM+ application to hold global auto-incremented value?
...create an SQL table which holds counter value and a SP which auto increments table value and return current counter?
...create an application that holds a static variable and publishes that one via HLA-RTI?
fjdiewornncalwe 16-May-11 18:29pm    
I think the OP expects some sort of magic control to do this for him/her. They need to understand that the "form" does not make these numbers, something in the code behind does the work and the form just displays the results. I don't even want to mention that these numbers should come from an object that knows about the current data store and the values in it.
when handling the click event...

int newVal = 0;

if (textbox.text != string.empty)
{
   string lastValStr = textbox.text.substring(5);
   if (Int.TryParse(lastValStr, out newVal))
      newVal++;
}

textbox.text = String.Format("{0}_{1}", DateTime.Now.Year, newVal);
 
Share this answer
 
Comments
shonezi 19-May-11 5:11am    
this is ok but I always get zero at the end because newVal = 0, it doesnt change to to next number upon adding data
fcronin 19-May-11 13:17pm    
If your textbox contains "2011_0" after the first run, it should contain "2011_1" after running through this code again. Step through it and see what the values are as it progresses to try and find the issue.

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