简体   繁体   English

返回上一个ID(IDENTITY)在插入行VB.NET MySQL上

[英]Return Last ID (IDENTITY) On Insert row VB.NET MySQL

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())

I want to return the AUTO_INCREMENT value of the current insert, and show in a msgbox. 我想返回当前插入的AUTO_INCREMENT值,并显示在msgbox中。

You can use an double Query and use the function LAST_INSERT_ID() After run your first query to get the last current query: 您可以使用双查询并使用函数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)

您可以通过MySQL查询获取表的AUTO_INCREMENT值,然后在MsgBox中显示该值

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

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