Example : How to Auto Increment the Serial number value in a text box.
NB: Put database connectivity code here first and write the code either at form load event or other proper event.

Sub Autoincrement()
   Dim x As String = ""
   Dim p1,p2 As Integer
   p1 = 0
   cn.Open()
   cm.CommandText = "select slno from sale"
   rdr = cm.ExecuteReader()
      While (rdr.Read())
         x = rdr("slno").ToString
         p2 = Val(x)    'Val() convert String into Integer.
         If p2 > p1 Then
            p1 = p2
         End If
      End While
   cn.Close()

   Textbox1.Text = p1 + 1
End Sub

NB : Call and Use Autoincrement() Subroutine at proper places as per need in the program.

Loading

Categories: VB .Net Codes

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.