본문 바로가기
MySql

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

by 베이스 공부 2020. 9. 18.
반응형
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에 표시하고 싶습니다.

 

해결 방법

 


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://stackoverflow.com/questions/9791156

 

 

반응형

댓글