为什么adParamOutput参数不包含一个值后执行 [英] Why adParamOutput parameter doesn't contain a value after execute

查看:518
本文介绍了为什么adParamOutput参数不包含一个值后执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP经典与ADO,连接到SQL Server 2008。

I am using ASP classic with ADO, connecting to SQL Server 2008.

我继承了这个code,它是如此错位的,我会尝试重新创建的相关部分。如果您需要更多的细节或我留下的东西了,请让我知道。

I inherited this code and it is so mangled that I will try to recreate the relevant parts. If you need more detail or I left something out, please let me know.

我创建一个命令,并添加参数

I create a command and add parameters

oCmd.CommandType = adCmdStoredProc
...
oCmd.Parameters.Append oCmd.CreateParameter("@MyOutputParam", adInteger, adParamOutput, 4, NULL)

后来,我打开一个读者从命令:

Later, I open a reader from that command:

oRS.Open oCmd, , adOpenForwardOnly, adLockReadOnly

之后,尽管口服补液盐是开放的,但我读过的任何记录或值之前,我尝试使用,以获取输出参数的值 有一个以下线路:

After that, while oRS is open but before I've read any records or values, I try to get the output parameter's value using one of the lines below:

val1 = oCmd("@MyOutputParam")
val2 = oCmd("@MyOutputParam").Value
val3 = oCmd.Parameters("@MyOutputParam").Value

这三个(VAL1,val2中,VAL3)变量DB NULL。

All three (val1, val2, val3) variables are DB NULL.

我已经证实,运行在查询分析器的SP值返回到@MyOutputParam参数:

I have confirmed that running the SP in query analyzer returns a value to the @MyOutputParam parameter:

declare @p33 int
exec usp_GetResultAndOutput 1, 2, 3, @p33 output
select @p33

这将返回我的期望记录的记录并显示在一行数字的第二个记录集。

That returns a recordset of my expected records and a second recordset showing a number in a single row.

我甚至试过试图获取输出参数调用之前和rs.NextRecordset没有工作。

I've even tried calling rs.NextRecordset before attempting to get the output parameter and that didn't work.

有没有办法,我必须处理输出参数一些其他的方式?

Is there some other way that I need to be handling Output parameters?

是不是好,我返回记录集和输出参数?

Is it okay that I am returning a recordset and output parameters?

推荐答案

不能检索输出参数,直到全部记录集枚举,直到结束。试想想,怎么可能在客户端可能在执行完成之前检索参数的产值?在执行()调用只是启动的执行,该批次继续进​​行,直到所有的结果返回在服务器上执行。虽然客户端遍历由 SELECT生成的ResultSet 批次正在执行的SELECT。输出参数的值仅在批次的结束的是已知的。因此不可能知道输出参数值,直到批次完成后,这意味着所有语句已执行,这又要求所有结果集被客户消耗(迭代)。

Output parameters cannot be retrieved until all the recordsets are enumerated until the end. Just think, how could the client possibly retrieve the output value of a parameter before the execution finishes? The Execute() call is simply starting the execution, the batch continues to execute on the server until all results are returned. While a client is iterating over a resultset produced by a SELECT the batch is executing that SELECT. The value of the output parameter is known only at the end of the batch. Therefore is not possible to know the output parameter value until the batch finished, which implies that all statements have executed, which in turn requires that all resultsets were consumed (iterated) by the client.

这是解析的结果集的规范形式:

This is the canonical form of parsing a set of results:

do
{
  while (rs.MoveNext)
  {
    // do something with the row
  }
} while (Not rs.NextRecordset Is Nothing)
// now is safe to read the out param
response.write oCmd("@MyOutput")

这篇关于为什么adParamOutput参数不包含一个值后执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆