ASP里取得存储过程的返回值问题!奇怪的问题。不是简单的返回值问题!
ASP里:
<%
Set oConn = Server.CreateObject("ADODB.Connection")
strConn="Provider=SQLOLEDB;User ID=sa;Initial Catalog=northwind;Data Source="& Request.ServerVariables("SERVER_NAME")
oConn.Open strConn
Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = "{call pageview(?,?,?)}"
oCmd.Parameters.Append oCmd.CreateParameter("int_pagenow", 3, 1)
oCmd.Parameters.Append oCmd.CreateParameter("int_pagesize", 3, 1)
oCmd.Parameters.Append oCmd.CreateParameter("int_pagecount", 3, 2)
oCmd("int_pagenow") = 1
oCmd("int_pagesize") = 20
set oRs=oCmd.Execute()'这里出现问题!当我把这行改成oCmd.Execute就可以输出参数oCmd("int_pagecount")啦。现在的问题是没有结果输出。如果我把oRs的记录集遍历出来的话,oCmd("int_pagecount")又可以正常显示了!真的不知怎么搞的。但我不想这时对oRs有任何操作,也不想额外写多句oCmd.Execute,因为执行多一次效率就低一倍嘛!
response.write oCmd("int_pagecount")
%>
存储过程(建立在SQL2000的示例数据库northwind上!):
CREATE PROCEDURE dbo.Pageview /* 记录集分页 */
(
@int_pagenow int=1, --第几页
@int_pagesize int=20, --每页记录数
@int_pagecount int output --页数
)
AS
set nocount on
declare @int_allid int
declare @int_beginid int,@int_endid int
declare @int_pagebegin int, @int_pageend int
select @int_allid=count(OrderID) from [Orders]--select 语句!!!!!!!!!!!!!!!!!!!!!!!!!!
select @int_pagecount=round((@int_allid+round((@int_pagesize-1)/2,0,1))/@int_pagesize,0,1)--得出页总数
set @int_beginid=(@int_pagenow-1)*@int_pagesize+1 --得出该页的第一个纪录Id
set @int_endid = @int_beginid+@int_pagesize-1 --得出该页的最后一个纪录的Id
--这里定义游标操作,但是不用临时纪录集,而且游标也不需要全部遍历所有纪录集。
declare cro_fastread cursor scroll
for select OrderID from [Orders] order by OrderID desc --select 语句!!!!!!!!!!!!!!!!!!!!!
open cro_fastread --打开游标
fetch absolute @int_beginid from cro_fastread into @int_pagebegin --将他的Id传给一个变量该页开始的Id
if @int_endid>@int_allid --这里要注意,如果某一页不足固定页数的纪录时。如只有一页纪录,而且纪录少于定义的数目。或者是最后一页时。。。
Begin
fetch last from cro_fastread into @int_pageend --直接将游标绝对定位到最后一条纪录,得出他的id号来。。。
end
else
Begin
fetch absolute @int_endid from cro_fastread into @int_pageend
End
--利用该页的第一个id和最后一个id得出中间的id来。。。。
select * from [Orders] where (OrderID between @int_pageend and @int_pagebegin) order by OrderID desc
--select 语句!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
close cro_fastread
deallocate cro_fastread
return
GO