我们如何在 msaccess 查询中获取最后插入的记录 [英] How do we get last inserted record in msaccess query

查看:36
本文介绍了我们如何在 msaccess 查询中获取最后插入的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从我的 vb.net 应用程序插入到 msaccess db.

I am inserting data from my vb.net application to msaccess db.

我对将最后插入的记录添加到表中的方式感到困惑.在 MS-SQL 中,我们得到了 @@IDENTITY,但它在 MSAccess 中对我不起作用.

I am confused in way of getting the last inserted record added to a table. IN MS-SQL we get @@IDENTITY for that but it didn't worked for me in MSAccess.

那么应该怎么做才能将最后插入的记录添加到表中?

so what should be do for getting the last inserted record added to a table?

推荐答案

示例:

Dim db As Database
Set db = CurrentDb

db.Execute "INSERT INTO Table1 (atext) Values('abc')", dbFailOnError

Dim rs As dao.Recordset

Set rs = db.OpenRecordset("select @@identity")
Debug.Print rs(0)

它确实要求表上有一个自动增量键.

It does require that there is an autoincrement key on the table.

这篇关于我们如何在 msaccess 查询中获取最后插入的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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