Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

auto increment

Question posted by: baccheekumar (Newbie) on July 25th, 2008 11:16 AM
hi
this is niraj i am doing a code to auto increment the employee number on button click event in a text box ....can any one help me for that.
the format has to be in the form like. 001-08 where 001 is employee code and 08 is the year. and that should be in vb.net
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
r035198x's Avatar
r035198x
Administrator
10,647 Posts
July 25th, 2008
11:33 AM
#2

Re: auto increment
What have you done so far?

Reply
baccheekumar's Avatar
baccheekumar
Newbie
2 Posts
July 25th, 2008
11:58 AM
#3

Re: auto increment
Quote:
Originally Posted by r035198x
What have you done so far?


on form load i have written the code as follows:
dim x as integer
cmd1 = New SqlCommand
cmd1.Connection = con
cmd1.CommandText = "select max(empno) from employee"
dr1 = cmd1.ExecuteReader
dr1.Read()
x = dr1.Item(0) + 1
dr1.Close()

and on button click :
txtno.Text = x
x = x + 1
but it increment the values like 1,2,3,4................like that

Reply
insertAlias's Avatar
insertAlias
Moderator
1,131 Posts
July 25th, 2008
01:55 PM
#4

Re: auto increment
OK, let me get this straight:
You want txtno.Text to contain something like 004-08, but x contains 4 right? You need to learn about string formatting. The link is for C#, but all of the concepts apply to VB.NET as well.

Reply
Reply
Not the answer you were looking for? Post your question . . .
183,969 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top .NET Forum Contributors