【发布时间】:2015-09-02 20:00:37
【问题描述】:
我最近遇到了 vba 更新语句,我一直在使用 Recordset.Edit 和 Recordset.Update 不仅可以编辑我现有的数据,还可以更新它。
我想知道两者的区别:recordset.update 和Update sql Vba 语句。我认为他们都做同样的事情,但我不知道哪个更有效以及为什么。
示例代码如下:
'this is with sql update statement
dim someVar as string, anotherVar as String, cn As New ADODB.Connection
someVar = "someVar"
anotherVar = "anotherVar"
sqlS = "Update tableOfRec set columna = " &_
someVar & ", colunmb = " & anotherVar &_
" where columnc = 20";
cn.Execute stSQL
这是用于记录集(更新和编辑):
dim thisVar as String, someOthVar as String, rs as recordset
thisVar = "thisVar"
someOthVar = "someOtherVar"
set rs = currentDb.openRecordset("select columna, columnb where columnc = 20")
do While not rs.EOF
rs.Edit
rs!columna = thisVar
rs!columnb = someOthvar
rs.update
rs.MoveNext
loop
【问题讨论】:
-
WHERE columnc = 20选择了多少行?一排?一百万行? -
假设是 1000+