VB SQL UPDATE 命令返回错误“运行时错误 424:需要对象。”

发布于 2024-11-03 08:06:49 字数 1030 浏览 1 评论 0原文

这是代码:

Dim tr As Transactions
Set tr = New Transactions

Dim ID As Integer
Dim name As String, username As String, password As String, activate As String

name = cmbName.Value
ID = tr.GetUserID(name)

If (AccountActivated = True) Then
    username = txtUsername.Value
    password = txtPassword.Value
    MsgBox name & " " & username & " " & password
    activate = "Yes"
Else
    username = ""
    password = ""
    activate = "No"
End If

tr.UpdateAccount name, username, password, activate 'ERROR HERE: Object required

这是我正在调用的函数:

 Public Function UpdateAccount(ByVal name As String, ByVal username As String, ByVal password As String, ByVal activation As String)
        Call connectDB
        sSQL = "update User set Username = '" & username & "', Password = '" & password & "', AccountActivated = '" & activation & "' where Name = '" & name & "'"
        MsgBox sSQL
        db.Execute sSQL
 End Function

Here's the code:

Dim tr As Transactions
Set tr = New Transactions

Dim ID As Integer
Dim name As String, username As String, password As String, activate As String

name = cmbName.Value
ID = tr.GetUserID(name)

If (AccountActivated = True) Then
    username = txtUsername.Value
    password = txtPassword.Value
    MsgBox name & " " & username & " " & password
    activate = "Yes"
Else
    username = ""
    password = ""
    activate = "No"
End If

tr.UpdateAccount name, username, password, activate 'ERROR HERE: Object required

Here;s the function I'm calling:

 Public Function UpdateAccount(ByVal name As String, ByVal username As String, ByVal password As String, ByVal activation As String)
        Call connectDB
        sSQL = "update User set Username = '" & username & "', Password = '" & password & "', AccountActivated = '" & activation & "' where Name = '" & name & "'"
        MsgBox sSQL
        db.Execute sSQL
 End Function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖公主 2024-11-10 08:06:49

为什么在这里使用“db”而在另一个问题上使用“CurrentDb”?始终使用显式选项进行编码。

为什么是function,改为sub,我不记得这是否会导致问题。

但最重要的是,不要使用从文本框中输入的文本来构建 sql 字符串,这很容易成为 SQL 注入的受害者,请使用参数。

Why here you use "db" and on the other question "CurrentDb" ? Always code using option explicit.

And why is function, change to sub, i don't remember if this could cause a problem.

But most important, dont use text inputed from text boxes to build a sql string, this makes it easy to be a victim of SQL injection, use parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文