ASP页面不显示存储过程OUTPUT

时间:2011-08-03 14:42:55

标签: sql stored-procedures asp-classic ado

我有一个ASP页面,调用带有返回值AND OUTPUT参数的存储过程。

输出参数没有显示,我不明白为什么:

<%
  dim Objrs, cmd
  set Objrs = Server.CreateObject("ADODB.RecordSet")
  set cmd = Server.CreateObject("ADODB.Command")
  set conn = Server.CreateObject("ADODB.Connection")
  conn.Open strConnect
  set cmd.ActiveConnection = conn
  cmd.CommandText="MKTG_Current"
  cmd.CommandType=adCmdStoredProc
  cmd.Parameters.Append cmd.CreateParameter("@added", 135, 2)
  cmd.Parameters.Append cmd.CreateParameter("@named", 200, 2, 50)

  set Objrs = cmd.Execute
%>
    </div>
    <div id="recent-news-box" class="rounded-corners-top dropshadow">
      <h3 class="border-dashed-b">Updated on: <%=Objrs.state%></h3>
      <div>
<%
    While Not Objrs.EOF
        Response.Write Objrs("Subject")
        Objrs.MoveNext
    Wend
  name_of_table = cmd.Parameters("@named").value
  added = cmd.Parameters("@added").value
  set cmd = nothing
  set Objrs = nothing
  conn.close
  set conn = nothing
        Response.Write name_of_table
        Response.Write added    
%>
          </div>
         </div>
      </div>

我尝试过更改输出项目的位置无效。

1 个答案:

答案 0 :(得分:0)

由于ADO将命令结果返回到记录集和输出参数的方式,因此存在一些笨拙。

在返回的记录集关闭后它们可用,因此该顺序应该有效:

  set Objrs = nothing

  name_of_table = cmd.Parameters("@named").value
  added = cmd.Parameters("@added").value

  set cmd = nothing
  conn.close
  set conn = nothing

  Response.Write name_of_table
  Response.Write added 

另一种方法是将代码保留为添加开关到客户端游标:

  conn.Open strConnect
  conn.CursorLocation = 3 '//aduseclient
  set cmd.ActiveConnection = conn

(如果未链接到类型库,请检查您的adCmdStoredProc的使用是否不应替换为其数值)