is there a way to do SELECT SCOPE_IDENTITY() in ADODB?

不问归期 提交于 2019-12-11 07:27:47

问题


With rs
    .AddNew ' create a new record
    ' add values to each field in the record
    .Fields("datapath") = dpath
    .Fields("analysistime") = atime
    .Fields("reporttime") = rtime
    .Fields("lastcalib") = lcalib
    .Fields("analystname") = aname
    .Fields("reportname") = rname
    .Fields("batchstate") = bstate
    .Fields("instrument") = instrument
    .Update ' stores the new record        
End With

this is how i am adding records. is it possibel to do something lik ethis???:

With rs
    .AddNew ' create a new record
    ' add values to each field in the record
    .Fields("datapath") = dpath
    .Fields("analysistime") = atime
    .Fields("reporttime") = rtime
    .Fields("lastcalib") = lcalib
    .Fields("analystname") = aname
    .Fields("reportname") = rname
    .Fields("batchstate") = bstate
    .Fields("instrument") = instrument
     SCOPE_IDENTITY()  <----------------
    .Update ' stores the new record


End With

回答1:


After you have executed the Update command, the identity will be placed in the corresponding field in the recordset. You can read it from there.

Example:

id = .Fields("id")



回答2:


No, there is not.

You should make an explicit INSERT statement followed by a call to SCOPE_IDENTITY in the same batch.



来源:https://stackoverflow.com/questions/3533090/is-there-a-way-to-do-select-scope-identity-in-adodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!