我需要帮助。我想自动生成字母数字ID示例A / 001/2016,其中001应增加1,2016年代表使用vb 2010年 我想要像A / 001/2016,A / 002/2016,A / 003/2016
这是我的代码:
Private Sub autogenerate_ID()
Dim mysqlconnection As MySqlConnection
Dim command As New MySqlCommand
MySqlConnection = New MySqlConnection()
MySqlConnection.ConnectionString = " server = localhost; user id = root; password=; database = birth_and_death "
Command.Connection = MySqlConnection
mysqlconnection.Open()
Dim sqlquery = "select Max(Death_ID) from decease "
command.CommandText = sqlquery
Dim ID As Integer
Dim value As String
Dim d As String = DateTime.Now.ToString("yyyy")
value = command.ExecuteScalar().ToString()
If String.IsNullOrEmpty(value) Then
value = "D/001/1990"
End If
value = value.Substring(3)
Int32.TryParse(value, ID)
ID = ID + 1
value = "D/" + ID.ToString("D3") + "/" + d
' value = "A/" + Convert.ToString(ID) + "/" + d
TxtDeathID.Text = value
command.Dispose()
mysqlconnection.Close()
mysqlconnection.Dispose()
End Sub
答案 0 :(得分:0)
试试这个:
If IsDBNull(Command.ExecuteScalar) = False Then
Dim t() As String = Split_Serie(Command.ExecuteScalar)
Value = "A/" & Format(t(1) + 1, "000") + "/" & Year(Now.Date)
Else
value = "D/001/1990"
End If
并且您必须创建一个将您的鳕鱼分割为:
的函数 Public Function Split_Serie(num As String) As String()
Dim t() As String
t = Split(num, "/")
'Part1 = t(0)
'Part2 = t(1)
'Part2 = t(3)
Return t
End Function