dubbelpunt
03-19-2012, 05:08 AM
Hi,
I have a function to determine the last insert id at mysql. Here is the function:
Function GetInsertId(cnVerbinding As ADODB.Connection) As String
Dim qryLastid As String, insertid As String
Dim rsLastid As ADODB.Recordset
qryLastid = "select last_insert_id()"
Set rsLastid = New ADODB.Recordset
rsLastid.Open qryLastid, cnVerbinding, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not rsLastid.EOF Then
insertid = rsLastid.Fields(0).Value
End If
GetInsertId = insertid
End Function
When I output the variable value of insertid within the function, I have the correct value. When I output the variable after calling the function, the function returns 0 or sometimes it doesn't return out of the function.
Anyone knows what causes this problem?
I have a function to determine the last insert id at mysql. Here is the function:
Function GetInsertId(cnVerbinding As ADODB.Connection) As String
Dim qryLastid As String, insertid As String
Dim rsLastid As ADODB.Recordset
qryLastid = "select last_insert_id()"
Set rsLastid = New ADODB.Recordset
rsLastid.Open qryLastid, cnVerbinding, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not rsLastid.EOF Then
insertid = rsLastid.Fields(0).Value
End If
GetInsertId = insertid
End Function
When I output the variable value of insertid within the function, I have the correct value. When I output the variable after calling the function, the function returns 0 or sometimes it doesn't return out of the function.
Anyone knows what causes this problem?