我目前使用 If Not RS.EOF 和 Not RS.BOF is a DAO Recordset,但我不能在新的 SQL 后端环境中使用 DAO。代码如下:
Function CloseSession()
'This closes the open session
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM Tbl_LoginSessions WHERE fldLoginKey =" & LngLoginId)
If Not Rs.EOF And Not Rs.BOF Then
Rs.Edit
Rs.Fields("fldLogoutEvent").Value = Now()
Rs.Update
Rs.Close
End If
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Tbl_Users] WHERE PKUserID =" & LngUserID)
'Flag user as being logged out
If Not Rs.EOF And Not Rs.BOF Then
Rs.Edit
Rs.Fields("fldLoggedIn").Value = 0
Rs.Fields("FldComputer").Value = ""
Rs.Update
Rs.Close
End If
Set Rs = Nothing
End Function
本质上,我已经开始在 ADODB 中编写代码。然而,在互联网上为 ADODB 研究 If Not RS.EOF 主题时,我完全没有成功。是否有人了解 RS.EOF 和 RS.BOF 的使用情况,这可能有助于我重写的困境?
Function CloseSession()
'/This closes the open session
'/Define the OLE DB connection string.
StrConnectionString = "DRIVER=SQL Server;SERVER=dbswd0027;UID=Mickey01;PWD=Mouse02;DATABASE=Regulatory;"
'/Instantiate the Connection object and open a database connection.
Set cnn = CreateObject("ADODB.Connection")
cnn.Open StrConnectionString
Dim strSQL1 As String
Dim strSQL2 As String
Dim StrLoginName As String
Dim StrComputerName As String
'/passing variables
StrComputerName = FindComputerName
strLoggedIn = "False"
'/Declaring what table you are passing the variables to
strSQL1 = "Update tTbl_LoginSessions SET fldLogoutEvent = '" & Now() & "'" & _
" WHERE fldLoginKey = " & LngLoginId
'/Declaring what table you are passing the variables to
strSQL2 = "Update tTbl_LoginUsers SET fldLoggedIn = '" & strLoggedIn & "', fldComputer = '" & StrComputerName & "'" & _
" WHERE intCPIIUserID = " & LngUserID
cnn.Execute strSQL1, , adCmdText + adExecuteNoRecords
cnn.Execute strSQL2, , adCmdText + adExecuteNoRecords
'/close connections and clean up
cnn.Close
Set cnn = Nothing
End Function