[ACCEPTED]-Return Last ID (IDENTITY) On Insert row VB.NET MySQL-identity

Accepted answer
Score: 14

You can use an double Query and use the 2 function LAST_INSERT_ID() After run your first query to 1 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())

Score: 2

Bit late to the party but after


Produces 1 the last insert id.

Score: 1

You can fetch the AUTO_INCREMENT value for 2 a table through a MySQL query and then show that in 1 your MsgBox

More Related questions