自动生成字母数字 [英] auto generate alphanumeruc number
问题描述
美好的一天专家!,
我想问一下是否有人可以帮我处理我的代码。我想显示一个自动生成的字母数字这样的数字:
OR06161400001
这是我的代码是这样的:
Good Day Experts!,
i would like to ask if anyone can help me with my code. i want to display a auto-generating alphanumeric numbers like this:
OR06161400001
which is in my code is something like this:
Dim con As New SqlConnection(ConnectString())
Dim cd As New SqlCommand
Dim lrd As SqlDataReader
Try
con.Open()
cd.Connection = con
cd.CommandText = "SELECT count(ornumber) as co FROM BlueRoomTransactions"
lrd = cd.ExecuteReader()
While lrd.Read()
ornum = Convert.ToString(lrd("co"))
End While
Catch ex As Exception
Finally
con.Close()
End Try
ornum = ornum + 1
txtORNumber.Text =OR+ Date.Today.ToString(MMddyy)++ ornum.ToString.PadLeft(5,0)
我想要的是在日期之后显示第一个字母A。然后如果它达到100,则字母A变为B。
i尝试使用此代码,但我得到的是最后一个字母。
txtORNumber.Text = "OR" + Date.Today.ToString("MMddyy") + "" + ornum.ToString.PadLeft(5, "0")
what i want is to display the first alphabet "A" after the date.then if it reach 100,Letter "A" becomes "B".
i tried using this code but all i get is the last alphabet.
Dim iChar As Integer
For iChar = Asc("a") To Asc("z")
MsgBox(Chr(iChar))
Next iChar
谢谢。
Thanks.
推荐答案
看起来你想自己生成id,这绝不是一个好主意。没有必要让id更复杂。如果您希望人们能够在上下文中传递ID,添加前缀以使其清楚它属于哪个表,则前缀很好。但即便如此,你也可以给他们一个实体。这将使所有人更容易理解。
祝你好运!
Looks like you want to generate the id's yourself which is never a good idea. There is no need to make the id's more complex then they are. A prefix is fine when you want people being able to communicate id's in context, adding the prefix to make it clear to what table it belongs. But even then you could just give them an entity. This would make it even more easier and understandable for all.
Good luck!
这篇关于自动生成字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!