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

时间:2011-04-26 03:07:42

标签: vb.net ms-access-2007 dao

以下是代码:

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

1 个答案:

答案 0 :(得分:1)

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

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

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