大家好,我是这个网站的新手,我想得到你们的帮助。我目前正在处理我的项目,我使用的是VB.net 2010.我需要帮助我自动生成的ID。
我希望我的ID像这样: CAT001 CAT002 CAT003 等等。
答案 0 :(得分:1)
假设你有一个名为_idNumber的id号的计数器,那么你可以有类似的东西:
Dim idString as String = String.Format("CAT{0}", _idNumber.ToString("D3"))
答案 1 :(得分:0)
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 = your database "
Command.Connection = MySqlConnection
mysqlconnection.Open()
Dim sqlquery = "select Max(ID) from yourtable "
command.CommandText = sqlquery
Dim ID As Integer
Dim value As String
value = command.ExecuteScalar().ToString()
If String.IsNullOrEmpty(value) Then
value = "CAT000"
End If
value = value.Substring(3)
Int32.TryParse(value, ID)
ID = ID + 1
value = "CAT" + ID.ToString("D3")
Txt.Text = value
command.Dispose()
mysqlconnection.Close()
mysqlconnection.Dispose()
End Sub