gpt4 book ai didi

sql - 链接表和 Ms Access 错误(运行时错误 '3622' : dbSeeChanges/Identity column )

转载 作者:行者123 更新时间:2023-12-04 00:42:44 24 4
gpt4 key购买 nike

我正在尝试输出所有链接表的名称,包括它们的字段(日期/时间)和字段值。

下面的代码可以输出第一个表,字段名和它们的第一个值,而不是所有值,虽然当它到达下一个链接表时,我得到这个错误

Run-time Error '3622' 
You must use the dbSeeChanges option with OpenRecordSet when accessing a SQL Server table that has an IDENTITY column.

这是我的代码

Private Sub btnGetFields_Click()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim f As Field
Dim rst As DAO.Recordset
Dim numField As Integer

Set db = CurrentDb

For Each tdf In db.TableDefs

If Left$(tdf.Connect, 9) = "ODBC;DSN=" Then

Set rst = CurrentDb.OpenRecordset(tdf.Name)
numField = rst.Fields.Count

Debug.Print "Table: " & tdf.Name
For index = 0 To numField - 1
If rst.Fields(index).Type = dbDate Then

Debug.Print "Field: " & rst.Fields(index).Name; " Value : "; rst.Fields(index).Value
End If
Next



End If

Next

Set tdf = Nothing
Set db = Nothing

End Sub

我读到一些东西,如果我正在使用 sql 表,我应该使用 ADO?有什么想法吗?

最佳答案

你可以继续使用你现有的DAO代码,只是改变一下

Set rst = CurrentDb.OpenRecordset(tdf.Name)

Set rst = CurrentDb.OpenRecordset(tdf.Name, dbOpenSnapshot)

这会打开一个静态只读 Recordset,因此不需要 dbSeeChanges

关于sql - 链接表和 Ms Access 错误(运行时错误 '3622' : dbSeeChanges/Identity column ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com