// This is what i've tried first but i want the vice versa of this with current year. Public Sub incrPR() Dim curValue As Integer Dim result As String Dim s As String = "PR" Dim yr As String = Now.Year.ToString() Using con As SqlConnection = New SqlConnection(ConString) con.Open() Dim cmd = New SqlCommand("Select MAX(SpecialOrderNo) FROM SpecialOrder", con) result = cmd.ExecuteScalar().ToString() cmd.Parameters.Clear() If String.IsNullOrEmpty(result) Then result = "PR000" End If result = result.Substring(3) Int32.TryParse(result, curValue) curValue = curValue + 1 result = s & curValue.ToString("D3") txtno.Text = result End Using End Sub What I have tried: Public Sub incrPR() Dim curValue As Integer Dim result As String Dim yr as string = "-" & Now.Year.ToString() Dim s As String = "-PR" Dim yr As String = Now.Year.ToString() Using con As SqlConnection = New SqlConnection(ConString) con.Open() Dim cmd = New SqlCommand("Select MAX(SpecialOrderNo) FROM SpecialOrder", con) result = cmd.ExecuteScalar().ToString() cmd.Parameters.Clear() If String.IsNullOrEmpty(result) Then result = "000" End If Int32.TryParse(result, curValue) curValue = curValue + 1 result = curValue.ToString("D3") & yr & s txtno.Text = result End Using End Sub //Sample output: 001-2018-PR but not number is not increasing //Expected sample output: 001-2018-PR, 002-2018-PR, 003-2018-PR
New SqlCommand("Select MAX(SpecialOrderNo) FROM SpecialOrder", con)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)