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())
您可以使用双查询并使用函数
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)