Home » excel » Getting last insert id in Excel ADODB connection to MySQL database

Getting last insert id in Excel ADODB connection to MySQL database

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have the following code to insert items into a MySQL database from an Excel form.

Set rs = New ADODB.Recordset
ConnectDB
With wsWorkBook
    strSQL = "INSERT INTO work_order (job_status, job_description, system_id) VALUES ....;"
    rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic
    ' word_order.id
End With

How can I get the last insert id of that line, which is in the work_order.id column?

How to&Answers:

Try using the LAST_INSERT_ID() – operator in a following SQL-Statement:

SELECT LAST_INSERT_ID();