you have to close the recordset before retrieving the output valueSet Rs = cmdTemp.Execute
if RowCount>0 thenWhile Not RS.EOFfor each Field in RS.Fields
Response.Write Field.Name & "=" & Field.Value & "<br>" & vbCRLF
Next
Response.Write "<br>"
RS.MoveNext
Wendend ifRS.Close
RowCount=cmdTemp("@RowCount")
Response.Write cmdTemp.Parameters("@RowCount").Value

解决方案 »

  1.   

    1. do you really need rowcount?? you can try like this:Set Rs = cmdTemp.Execute
    While Not RS.EOFfor each Field in RS.Fields
    Response.Write Field.Name & "=" & Field.Value & "<br>" & vbCRLF
    Next
    Response.Write "<br>"
    RS.MoveNext
    Wend
    RS.Close
    2. if you insist, you can change your stored procedure like this:select @RowCount=count(id) from linking where sitename like @key_string or jiji like @key_stringselect @RowCount as RowCount.....then inside your asp, you can try
    ....Set Rs = cmdTemp.Execute
    RowCount = RS("RowCount")
    set RS =RS.NextRecordset
    if RowCount>0 then
    While Not RS.EOF
    for each Field in RS.Fields
    Response.Write Field.Name & "=" & Field.Value & "<br>" & vbCRLF
    Next
    Response.Write "<br>"
    RS.MoveNext
    Wend
    end if
    RS.Close
      

  2.   

    返回行数是一定需要的。我知道在这里可以省略。是画蛇添足。但我这个行数的用处不在这。主要是拿来做分页用的。你的下面这段改的思路很清晰。我能理解。你的意思是先把@rowcount先存成一条记录显示,然后先取得这个记录,再向下移动游标再进行显示。不过我试了再存储过程里加上select @RowCount as RowCount,提示出错。不知这句该如何加?不过我自己也想到了好的方法:Set Rs = cmdTemp.Execute
    GetString = Rs.Getrows()
    Rs.Close
    RowCount=cmdTemp("@RowCount")把记录集先保存个一个数组里,再进行处理,呵呵。不过还是要谢谢你,希望继续以上的问题,怎么以你的理路做?不一定采用,但多学学别人的思路是好的。还有你能不能解决在7.0里以上的存储过程出错,不能用"*"乘号运算符?
      

  3.   

    CREATE procedure search_query_splitpage
    @Key nvarchar(200) ,
    @CurrentPage int,
    @PageCount int,
    @RowCount int OUTPUT
    as
    set nocount on
    ...
    exec('drop table ##Tab' + @TimeName)
    set oncount off
      

  4.   

    上面的。请指教set nocount的意思和用法?
      

  5.   

    我按你上面的加set nocunt on 提示语法错误!
      

  6.   

    你的这段有错误
    cmdTemp.Parameters.Append cmdTemp.CreateParameter("@Key",adVarChar,adParamInput,200,"Key")
    cmdTemp.Parameters.Append cmdTemp.CreateParameter("@CurrentPage",adInteger,adParamInput,,iVal)
    cmdTemp.Parameters.Append cmdTemp.CreateParameter("@PageCount",adInteger,adParamInput,,iVal)
    cmdTemp.Parameters.Append cmdTemp.CreateParameter("@RowCount",adInteger,adParamOutput,,oVal)存储过程默认的第一个参数应该是return参数,你在这里没有定义他,所以你取不会返回纪录集,而你直接执行存储过程时,ado帮你做了处理,所以可以执行。
      

  7.   

    上面的你说的不对。我也曾用过用return取得返回值。也行不通的。你看清楚我的问题了。我现在是记录集和返回值不能同时取得的问题当关了记录集就可以了。