Output parameters not updated after ExecuteReader()
When I run cmd.ExecuteScalar() or cmd.ExecuteNonQuery() the Output and InputOutput parameters开发者_运维知识库 on the command object get updated from the changes in the stored procedure. However the same does not happen for cmd.ExecuteReader(). This is happening on both Sql Server and MySql Connections. Is this behavior by design?
Hey this may help you. clicky...
It appears this can possibly be an issue under certain circumstances.
The output parameters are only available after you read to the end of the recordset.
For example, in this procedure:
alter procedure db.TestProc(@p int output)
as
select 1
select 1
set @par = 1
The database will only set @par after you've read both recordsets. The database doesn't even execute the second SELECT before you're done reading the first. It is streaming results as you request them.
You should be able to retrieve the value via an Output parameter. Take a look at this MS Support article and see if your issue is one of those mentioned: link text
Also, what are you trying to return? If it's just a single value, it would be worth using ExecuteScalar() rather than ExecuteReader().
精彩评论