简体   繁体   English

Microsoft Visual Studio 2017 - 在文本框中自动生成 ID

[英]Microsoft Visual Studio 2017 - Auto generating ID inside a text box

I would like to add details to my table (sales table) where the sales ID starts from "SS1" and increments after each update.我想向我的表(销售表)添加详细信息,其中销售 ID 从“SS1”开始并在每次更新后递增。 How do I code such that the vb does not crash when the table is still empty?我如何编码,以便当表仍然为空时 vb 不会崩溃?

Private Function generate_id() As String
    '   Dim lastid As String = run_sql_query("SELECT MAX(FLD_ORDER_ID) AS LASTID FROM TBL_ORDER_A167640").Rows(0).Item("LASTID")
    '  Dim newid As String = "OR" & Mid(lastid, 3) + 1
    'Return newid
End Function

The code inserted will crash if the table is empty for say I wish to start from SS1.如果表为空,例如我希望从 SS1 开始,则插入的代码将崩溃。 Please help !请帮忙 ! :( :(

If I'm not wrong in what you want, a way to do that might be:如果我对您的要求没有错,那么这样做的方法可能是:

Private Function generate_id() As String
        Dim lastid As Integer = CInt(run_sql_query("SELECT COUNT(FLD_ORDER_ID) AS LASTID FROM TBL_ORDER_A167640").Rows(0).Item("LASTID")) + 1
        Return "S1_" & CStr(lastid)
End Function

However is better to use an autoincremental ID/index as prefix numeric for your new id after “S1_”.但是,最好在“S1_”之后使用自动增量 ID/索引作为新 ID 的前缀数字。 Like this “S1_” & Select MAX( [autoncrementalID] ) as NUMID ....像这样“S1_” & Select MAX( [autoncrementalID] ) as NUMID ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM