我一直在使用ADO VBScript,它需要接受参数并将这些参数合并到传递数据库的Query字符串中.当记录集对象尝试打开时,我不断收到错误.如果我传递没有参数的查询,记录集将打开,我可以处理数据.当我通过调试器运行脚本时,命令对象不显示参数对象的值.在我看来,我错过了与Command对象和Parameter对象相关联的东西,但我不知道是什么.这里有一些VBScript代码:
...
'Open Text file to collect SQL query string'
Set fso = CreateObject("Scripting.FileSystemObject")
fileName = "C:\SQLFUN\Limits_ADO.sql"
Set tso = fso.OpenTextFile(fileName, FORREADING)
SQL = tso.ReadAll
'Create ADO instance'
connString = "DRIVER={SQL Server};SERVER=myserver;UID=MyName;PWD=notapassword; Database=favoriteDB"
Set connection = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
connection.Open connString
cmd.ActiveConnection = connection
cmd.CommandText = SQL
cmd.CommandType = adCmdText
Set paramTotals = cmd.CreateParameter
With paramTotals
.value = "tot%"
.Name = "Param1"
End With
'The error occurs on the next line'
Set recordset = cmd.Execute
If recordset.EOF …Run Code Online (Sandbox Code Playgroud)