sekedar nambah postingan, kali ini penulis akan me-share cara membuat autonumber di vb net.
untuk sample dan keterangan source code berikut penulis mempunyai :
1. ms_category : nama Table
2. no_cat : nama column
3. txtID : control textbox untuk menampilkan hasil autonumber
Berikut source code nya :
Private Sub autocode()
Dim kiri As String = "CAT-"
Dim nocat As String
Dim counter As Integer
cmd = New SqlCommand("SELECT count(no_cat) as jum FROM ms_category", conn)
rd = cmd.ExecuteReader()
rd.Read()
cmd.Dispose()
rd.Close()
If rd.Item("jum") < 1 Then
nocat = "01"
Else
cmd = New SqlCommand("SELECT Max(Right(no_cat,2))as maxcat FROM ms_Category", conn)
rd = cmd.ExecuteReader()
rd.Read()
cmd.Dispose()
rd.Close()
counter = rd.Item("maxcat") + 1
nocat = Microsoft.VisualBasic.Left("00", 2 - Len(CStr(counter)).ToString) & CStr(counter)
End If
TxtID.Text = kiri & nocat
End Sub
0 comments:
Post a Comment