传递 SQL 结果作为 VBScript 对象的参数

Passing a SQL result as an argument for a VBScript object

我目前正在开发一个现有的 .Asp 程序,其中包含以下代码段:

Dim strRel_Report_Location
Dim rs, sql, blnReportExists
Dim strUID
Dim intMonth, intYear

sql = "Select NewID() AS UID"
Set rs = DB.Execute(Sql)
strUID = rs("UID")


strRel_Report_Location = "/Admin/Reports/Temp/t" & strUID & ".html"

我的问题是,如何将字符串 "UID" 作为参数传递给对象 'rs'?人们可以很容易地从代码中推断出其意图是将结果 "NewID()" 调用传递到语句中指定的路径:

strRel_Report_Location = "/Admin/Reports/Temp/t" & strUID & ".html"

任何启发将不胜感激,因为我不想只对我正在使用的代码做出假设。

我确定这是你们的上篮,但感谢你们的帮助!

我必须在这里做一个假设,因为你永远不会显示 DB 变量是如何创建的。我假设您正在使用直接 ADO,因为您代码中的调用签名与之匹配。

同样,您可能正在使用 Ado Command instance which has the method Execute. This method takes a sql string, executes it on the database server, and then returns a Recordset,其中包含已执行查询的结果。记录集有一个带有列名称的索引器,使用该索引器您可以获取列中的值。

如果您想了解有关此代码的更多信息,开始阅读有关如何使用 ADO 的内容会有所帮助。