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

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)

Leave a Comment