Click here to Skip to main content
15,920,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I am creating a form in windows application using vs2008. I have use one text box and one button. when i press the button, the text box will have to show the last value stored in table.For example,Employee table has the column named as ID.In that column(ID) has 6 ids. Now when i press the button,that text box should show 6.

Thanks & Regards

Updated 4-Aug-11 1:35am
Herman<T>.Instance 3-Aug-11 9:15am    
please show your code
Viswanthan.M. 3-Aug-11 9:20am    
I don't have any code.. this is my please give me the code
Corporal Agarn 3-Aug-11 9:16am    
Are you storing just the last value or a history of values?
Viswanthan.M. 3-Aug-11 9:21am    
i will store every value after increment.

1 solution

To make this general purpose, you need to convert test to int and back again: fortunately this is easy as .NET provides the int.Parse[^] and ToString[^] methods respectively.

Since this is your homework, you can write the code!

1) Set the initial value of your TextBox to "1"
2) In your Button.Click event handler, read the value of your TextBox Text property and check it has some data. If it does, use the Parse methods to convert it to an integer.
3) Save the value to your database - you will probably need a SqlConnection and a SQLCommand objects. Your lecture notes should cover this part.
4) If it saved ok, add one to the integer, and set the TextBox.Text property to the new value using the ToString method.
5) If it didn't explain why to the user!
Share this answer

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