[英]Ado.net running SQL Server stored procedure can't retrieve output value when using ExecuteReader
param.Add(new SqlParameter("@Count", SqlDbType.Int) { Direction = ParameterDirection.Output });
using(var dataset = MsSqlHelper.ExecuteDataset(SqlConn.Conn, CommandType.StoredProcedure, "GetList", param.ToArray()))
{
// Count.Value is not NULL
}
using (SqlDataReader dr = MsSqlHelper.ExecuteReader(SqlConn.Conn, CommandType.StoredProcedure, "GetList", param.ToArray()))
{
// Count.Value is NULL
}
There is an output value in my stored procedure. 我的存储过程中有一个输出值。
If I use ExecuteReader
, the value of param Count
is null. 如果我使用ExecuteReader
,则参数Count
值为null。 But if I change method ExecuteReader
to ExecuteDataset
, then I can get value of Count
. 但是,如果我将ExecuteReader
方法更改为ExecuteDataset
,则可以获得Count
值。
Why is there no value when I use ExecuteReader? 为什么使用ExecuteReader时没有价值?
By the way, nothing has changed in my example except ExecuteDataset
/ ExecuteReader
. 顺便说一下,在我的示例中,除了ExecuteDataset
/ ExecuteReader
之外,没有任何改变。
You should check the output parameter value after the reader has been closed (ie after the using block), or after reading to the end of the data. 关闭阅读器后(即在using块之后),或在读取到数据末尾之后,应检查输出参数值。 See this KB article . 请参阅此知识库文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.