Dim getcode As String = "0"
cmd = New MySqlCommand()
cmd.Connection = con
cmd.CommandText = "SELECT * FROM deteilssell ORDER BY no_sell DESC"
Try
con.Open()
Dim reader As MySqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
If (reader.HasRows = True) Then
While reader.Read()
getcode = (reader.GetString(reader.GetOrdinal("no_sell")))
End While
End If
reader.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
If (getcode = "0") Then
TextBox1.Text = "AA-0000001"
ElseIf (getcode <> "0") Then
Dim totalcode As String = getcode.Count - 7
Dim oldnum As String = getcode.Substring(getcode.Length - totalcode)
TextBox1.Text = "AA-" + Format(oldnum + 1, "0000000").ToString
End If