auto increment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baccheekumar
    New Member
    • Jul 2008
    • 2

    auto increment

    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
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What have you done so far?

    Comment

    • baccheekumar
      New Member
      • Jul 2008
      • 2

      #3
      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.CommandTex t = "select max(empno) from employee"
      dr1 = cmd1.ExecuteRea der
      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

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        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.

        Comment

        Working...