我正在使用 Access 2007 并且有一些链接到 mySQL 数据库的表。我正在使用 DAO 将记录插入到 mySQL 链接表中,并尝试使用 Select @@identity 检索插入的 PK,但该选择返回 0。
Dim sql As String
Dim oDB As Database
Set oDB = CurrentDb
sql = "INSERT INTO Quotes ( CustomerID ) SELECT 1 AS Expr1;"
oDB.Execute sql
If oDB.RecordsAffected <> 1 Then
MsgBox "cannot create new quote"
Exit Function
End If
Dim rsNewID As DAO.Recordset
Set rsNewID = oDB.OpenRecordset("SELECT @@IDENTITY") ' Create a recordset and SELECT the new Identity
Dim intNewID As Long
intNewID = rsNewID(0).Value ' Store the value of the new identity in variable intNewID
'This value is 0, why?
我见过另一个这样的问题,对我来说没有得到满意的回答