从函数返回记录集时出现溢出 6 错误

Overflow 6 error when returning recordset from function

我的函数接收参数并执行 sql 查询,returning 记录集,但它在 return.

上出错
Public Function ExecuteParameters(sql As String, ParamArray Params() As Variant) As ADODB.Recordset
    Dim cmd As New ADODB.Command
    Dim inputParam As Variant
    cmd.ActiveConnection = Procs.getConn
    cmd.CommandText = sql

    For Each inputParam In Params
        Set inputParam = cmd.CreateParameter(, GetParameterType(inputParam), adParamInput, Len(Nz(inputParam, " ")), inputParam)
        cmd.Parameters.Append inputParam
    Next inputParam

    cmd.CommandType = adCmdText

    'errors out on this line
    Set ExecuteParameters = cmd.Execute()
End Function

这段代码工作正常,直到第 return 行将记录集从函数中取出,它出错为 overflow。我从教程中获得了这段代码,但无法弄清楚问题出在哪里,因此非常感谢您的帮助。

从这里调用函数:

Public Function OnDelete()
    ExecuteParameters "DELETE * FROM ? WHERE ? = ?", "Students", "StudentID", 32
End Function

为此苦苦挣扎了三天,终于有人指出,只能将实际值作为参数传递,不能传递 table 或列名。问题出在函数调用上,而不是我最初认为的return。

更新代码:

Public Function OnDelete()
    ExecuteParameters "DELETE * FROM Students WHERE StudentID = ?", 32
End Function

希望这可以帮助别人节省我花费的时间...