ASP page not displaying Stored Procedure OUTPUT
I have 开发者_如何学Goan ASP page calling a stored procedure with returned values AND OUTPUT parameters.
The output parameters aren't displaying and I'm not understanding why:
<%
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>
I've tried changing the position of the output items to no avail.
There is some clunkiness because of the way ADO returns command results to both a recordset and as output paramaters.
They are available after the returned recordset is closed, so this order should work:
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
An alternative is to leave the code as it is add switch to a client side cursor with:
conn.Open strConnect
conn.CursorLocation = 3 '//aduseclient
set cmd.ActiveConnection = conn
(Also check that your use of adCmdStoredProc
should not be replaced with its numeric value if your not linked to a typelib)
精彩评论