以下是我的代码:
页面加载
Private Sub frm_addproduct_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
txt_id.Text = generate_id()
End Sub
生成ID
Private Function generate_id() As String
Dim lastid As String = run_sql_query("SELECT MAX(FLD_PRODUCT_ID) AS LASTID FROM TBL_PRODUCTS").Rows(0).Item("LASTID")
'MsgBox(lastid)
Dim newid As String = "" & Mid(lastid, 2) + 1
Return newid
End Function
我的问题是,当它在txt_id文本框中显示id时,例如最后一个id为 45 时,它只显示“6”,而它应该是“46”。这里缺少什么?
答案 0 :(得分:1)
Dim lastId as string = "SELECT MAX(FLD_PRODUCT_ID)+1 FROM tablename. . . .";
Return lastId
或者,如果数据库需要int,您也可以转换它。