VBA如何找到最后插入的id?
我有这样的代码:
With shtControleblad
Dim strsql_basis As String
strsql_basis = "INSERT INTO is_calculatie (offerte_id) VALUES ('" & Sheets("controleblad").Range("D1").Value & "')"
rs.Open strsql_basis, oConn, adOpenDynamic, adLockOptimistic
Dim last_id As String
last_id = "select last_insert_id()"
End With
字符串last_id 未填充。怎么了?我需要找到last_insert_id,以便我可以在其他查询中使用它。
I have this code:
With shtControleblad
Dim strsql_basis As String
strsql_basis = "INSERT INTO is_calculatie (offerte_id) VALUES ('" & Sheets("controleblad").Range("D1").Value & "')"
rs.Open strsql_basis, oConn, adOpenDynamic, adLockOptimistic
Dim last_id As String
last_id = "select last_insert_id()"
End With
The string last_id is not filled. What is wrong? I need to find te last_insert_id so I can use it in an other query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
打开记录集后,您必须添加 rs.movelast ,这应该会有所帮助
you have to add
rs.movelast
after you open the recordset, that should help您已设置要执行的sql语句,但未执行。
使用上述语句调用 rs.Open 来获取“last_insert_id”。
如果mysql支持单行多个sql语句,你可以这样做
You have set the sql statement to be executed, but have not executed it.
Call
rs.Open
with the above statement to get the 'last_insert_id` instead.If mysql supports multiple sql statements on single line, you could do