在插入行VB.NET MySQL上返回最后一个ID(IDENTITY) [英] Return Last ID (IDENTITY) On Insert row VB.NET MySQL
本文介绍了在插入行VB.NET MySQL上返回最后一个ID(IDENTITY)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
推荐答案
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)
这篇关于在插入行VB.NET MySQL上返回最后一个ID(IDENTITY)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文