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 中.
I want to return the AUTO_INCREMENT value of the current insert, and show in a msgbox.
您可以使用双查询并使用函数 LAST_INSERT_ID() 运行您的第一个查询以获取最后一个当前查询后:
You can use an double Query and use the function LAST_INSERT_ID() After run your first query to get the last current query:
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)
这篇关于在插入行时返回最后一个 ID (IDENTITY) VB.NET MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!