本文介绍了在插入行时返回最后一个 ID (IDENTITY) 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())
我想返回当前插入的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!