List:MySQL on Win32« Previous MessageNext Message »
From:William E. Sam Date:October 30 2005 10:16am
Subject:RE : getting ID back after an insert statement
View as plain text  
Dim NewID as Long

Dim cn as New ADODB.Connection

Dim rs as New ADODB.Recordset

Dim QueryString as string

.

.

Set up your ADODB Connection object

rs.ActiveConnection = cn

rs.CursorType = adOpenStatic

rs.CursorLocation = adUseClient



QueryString = "INSERT INTO .."

.

.



cn.Execute QueryString

rs.Open "SELECT LAST_INSERT_ID()"



If rs.AbsolutePosition <> -1 Then

    NewID = rs(0)

End If



Fredrick Bartlett wrote:

Yes, but for some reason doing it that way returned 0 records for me. That
is why I did the WHERE ID = last_insert_id()



The key is to use a client side cursor for the recordset . with
rs.CursorLocation = adUseServer the Query will return 0.

I think adUseServer is the default so you have to set it to adUseClient in
your code.



Regards







Thread
RE : getting ID back after an insert statementWilliam E. Sam30 Oct