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

前端之家收集整理的这篇文章主要介绍了返回上一个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中.

您可以使用双查询并使用函数 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)
原文链接:https://www.f2er.com/vb/255354.html

猜你在找的VB相关文章