I fail auto generate id on my textbox can someone pls help me take a look. i have tried many method to auto generate id on my textbox but when user success key in data to the database but my textbox id still fail auto generate. if i stop and stop and play the program again the id will continue.
Private Sub getNextNumber()
If Not app.State = ConnectionState.Open Then
'open connection
app.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
app.Close()
If dt.Rows.Count > 0 Then
txtID.Text = (Val(dt.Rows(0)(0)) + 1).ToString.PadLeft(10, CChar("A"))
Else
txtID.Text = "1".PadLeft(10, CChar("A"))
End If
End Sub
Private Function getLastNumber() As Integer
Dim cnn1 As New OleDb.OleDbConnection
cnn1.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=mydataX.mdb;"
If Not cnn1.State = ConnectionState.Open Then
'open connection
cnn1.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select top 1 cid from checker order by cid desc;", cnn1)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
cnn1.Close()
If dt.Rows.Count > 0 Then
Return CInt(Val(dt.Rows(0)(0)))
End If
Return 0
End Function
the textbox after user success key in data it should be auto change to BBBBBBBB37 but it fail to change
Below is a new code i create for auto id
Private Sub Number()
Dim ids As List(Of Integer) = New List(Of Integer)()
For i As Integer = 1 To 100
ids.Add(i)
Next
Dim idstring As String = "INV" & ids(count).ToString().PadLeft(4, "0"c)
txtID.Text = idstring
count += 1
End Sub