访问SQL更新记录 [英] Access SQL Update record

查看:61
本文介绍了访问SQL更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新表中的现有记录.

I need to update an existing record in a table.

我一直在尝试两种不同的方法,但是看不到我缺少的东西:

I have been trying two different methods but can't see what I am missing:

首次尝试是:

CurrentDb.Execute "UPDATE [MS Access;pwd=" & strPassword & ";database=" & DBpath & "\" & DBname & "].[" & tblengagement & "] SET [Close_Time] = #" & Time & "#, WHERE ID = '" & SessionID & "'"

第二次尝试:

CurrentDb.Execute " UPDATE [MS Access;pwd=" & strPassword & ";database=" & DBpath & "\" & DBname & "].[" & tblengagement & "] " _
        & "(Close_Time) VALUES " _
        & "(#" & Time & "#)" _
'        & "WHERE ID = '" & SessionID & "';"

收到错误: 语法错误

我的代码更新:

Dim strPassword As String
Dim DBpath As String
Dim DBname As String
Dim tblengagement As String

DBpath = "C:\Projects"
DBname = "Data.accdb"
strPassword = "1234"

tblengagement = "tbl_engagement"

'CurrentDb.Execute " UPDATE [MS Access;pwd=" & strPassword & ";database=" & DBpath & "\" & DBname & "].[" & tblengagement & "] " _
'        & "(Close_Time) VALUES " _
'        & "(#" & Time & "#)" _
'        & "WHERE ID = '" & SessionID & "';"

推荐答案

正确的代码:

CurrentDb.Execute "UPDATE [MS Access;pwd=" & strPassword & ";database=" & DBpath & "\" & DBname & "].[" & tblengagement & "] " _
              & "SET [Close_Time] = #" & Time & "# WHERE ID = '" & SessionID & "';"

问题出在哪里: 我在代码中留下了 ,将其删除后效果很好

What the problem was: I had left a , in my code, once removed it worked fine

这篇关于访问SQL更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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