Public Function autonumber()
Dim query As String
Dim xmyread As SqlDataReader
Dim xmycmd As SqlCommand
Dim nilaiawal, nilaiauto, nilaiakhir As String
query = "select nim from mahasiswa order by nim desc"
xmycmd = New SqlCommand(query, mycn)
xmyread = xmycmd.ExecuteReader
If xmyread.HasRows = True Then
xmyread.Read()
nilaiawal = xmyread.Item("NIM")
nilaiauto = Val(Mid(xmyread.Item("nim"), 4, 7)) + 1
nilaiakhir = "nim" & Right("0000000", 7 - nilaiauto.Length) & nilaiauto
Else
nilaiakhir = "NIM0000001"
End If
xmyread.Dispose()
Return nilaiakhir
End Function
SELAMAT MENCOBA
Comments
Post a Comment