Dim insert_coupon_query As String = ("INSERT INTO qa_discountcoupons (id, status_code) VALUES (AUTO_INCREMENT_ID, 5)") Dim cmd_query As New MySqlCommand(insert_coupon_query, objConn) Dim cmd_result As Integer = CInt(cmd_query.ExecuteScalar())
我想返回当前插入的AUTO_INCREMENT值,并在msgbox中显示。
您可以使用双重查询并使用函数LAST_INSERT_ID()在运行第一个查询以获取最新的当前查询之后:
Dim insert_coupon_query As String = ("INSERT INTO qa_discountcoupons (status_code) VALUES (5); SELECT LAST_INSERT_ID()") Dim cmd_query As New MySqlCommand(insert_coupon_query, objConn) Dim cmd_result As Integer = CInt(cmd_query.ExecuteScalar()) MsgBox(cmd_result)