在 Access 中选择 @@IDENTITY WHERE [英] Select @@IDENTITY WHERE in Access

查看:28
本文介绍了在 Access 中选择 @@IDENTITY WHERE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在 Access 数据库中获取活动用户提交的最后一个票证 ID.除非我在没有 WHERE 子句的情况下单独留在SELECT @@IDENTITY"中,否则这不起作用.我怎样才能让它与 WHERE 子句一起工作?

Trying to get the last ticket ID submitted by the active user in an Access database. This doesn't work unless I leave in "SELECT @@IDENTITY" by itself without the WHERE clause. How can I get it to work with the WHERE clause?

        'Pulls the last submitted ticket ID, and makes sure it was submitted by the active user to prevent a race condition scenario among multiple users
    Dim returnvalue As Integer = -1
    Dim custCMD As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT @@IDENTITY WHERE [Last Modified By] = '" & Environment.UserName & "';", connection)


    returnvalue = CType(custCMD.ExecuteScalar(), Integer)


    MsgBox(returnvalue)

推荐答案

您不需要 SELECT @@IDENTITY 中的 WHERE 子句,因为该命令返回最后生成的自动编号与您的命令关联的连接.在其他 PC 或您自己的应用程序的其他实例上运行的其他连接不存在竞争条件.不确定多线程,但如果您遵循最佳实践打开/使用/关闭连接,那么您就安全了

You don't need a WHERE clause in the SELECT @@IDENTITY because that command returns the last generated autonumber for the connection associated with your command. There is no race condition with other connections running on other pc or on other instance of your own application. Not sure about multiple threads but if you follow best practice to open/use/close the connection then you are on the safe side

这篇关于在 Access 中选择 @@IDENTITY WHERE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆