Output options are not updated after ExecuteReader ()

When I run cmd.ExecuteScalar () or cmd.ExecuteNonQuery (), the Output and InputOutput parameters in the command object are updated from the changes to the stored procedure. However, the same does not happen for cmd.ExecuteReader (). This happens on both Sql Server and MySql Connections. Is this design behavior?

+3
source share
3 answers

Hey, this can help you. clicky ...

It seems like this could be a problem in certain circumstances.

+8
source

The output parameters are only available after reading at 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

@par , . SELECT, . , , .

+1

You should be able to get the value through the Output parameter. Take a look at this article on MS support and see if your problem is one of those mentioned: link text

Also, what are you trying to return? If this is just one value, it would be useful to use ExecuteScalar () rather than ExecuteReader ().

0
source

Source: https://habr.com/ru/post/1720267/


All Articles