gpt4 book ai didi

mysql - VBA - MySQL UPDATE - 返回代码以确认更新是否完成

转载 作者:行者123 更新时间:2023-11-29 15:45:05 25 4
gpt4 key购买 nike

尝试在 Excel 中运行 MySQL 更新。

想要检查更新是否发生,即是否找到并更新了该行,或者该行不存在且更新了 0 行

尝试在 VBA 代码中找到 MySQL 的返回代码,但我一无所获!

c = 2
Do While Trim(MAIN.Cells(c, 1)) <> ""

sMyword = "UPDATE table1 SET price = 1.00 WHERE part = 'ABC';"
conn.Execute sMyword

If "did the update happen against the row" > 0 Then
MAIN.Cells(c, 3) = "Price UPDATED OK"
Else
MAIN.Cells(c, 3) = "Part NOT FOUND "
MAIN.Cells(c, 3).Interior.ColorIndex = 3 'Red
End If

c = c + 1

Loop

我希望获取SQL语句更新的行数sMyword

最佳答案

Execute 方法应在第二个参数 RecordsAffected 中返回受影响的记录。试试这个语法:

Dim RecordsAffected As Long
sMyword = "UPDATE table1 SET price = 1.00 WHERE part = 'ABC';"
conn.Execute sMyword, RecordsAffected
MsgBox RecordsAffected

引用:https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/execute-method-ado-connection?view=sql-server-2017

关于mysql - VBA - MySQL UPDATE - 返回代码以确认更新是否完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57149316/

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