Problem with proc return value... RRS feed

  • Question

  • User1635139880 posted
    I am running the Data Access App Block version 2.0 Anyone ever run into this: I have a proc that returns me an integer which represents the identity column of one of the tables updated. I have used the SqlHelper.ExecuteNonQuery as well as the SqlHelper.ExecuteScalar methods to get the integer return value, but always seem to get back a -1. The proc runs fine without any errors and returns the correct value when run in the query analyzer in Enterprise Manager. I have tried using both Return @@Identity as well as Select @@Identity to no avail. Anyone know of any bugs or such that would prevent the correct value from being returned???
    Tuesday, May 18, 2004 3:57 PM

All replies

  • User1119954915 posted
    I use SELECT @@IDENTITY all the time with the SQLHelper.ExecuteScalar method and don't run into any problems
    Friday, May 28, 2004 2:50 PM
  • User-480774808 posted
    Did you ever get this to work using SQLHelper.ExecuteNonQuery or is it that the only way to receive a return value is by using SQLHelper.ExecuteScalar? For exmple, when I SQLHelper.ExecuteNonQuery to delete a record with a SP, I Return 0 or Return 1 depending if the delete worked. However, I always get a -1.

    Any ideas?

    Thursday, September 15, 2005 12:01 PM
  • User1119954915 posted
    Are you understanding the difference in the results brought back by "ExecuteScalar" and "ExecuteNonQuery"?

    NonQuery will return the # of rows affected in an integer value

    Scalar returns the first column of the first row of data in a generic "Object"

    Thursday, September 15, 2005 2:21 PM
  • User-480774808 posted
    Thank you for your reply. I do understand the differences, however, I keep getting back a -1 when using ExecuteNonQuery. Why am I getting a -1. Tell me, should I now be using ExcuteScalar for perform delete SP? This way I can return whatever value I want..

    Thursday, September 15, 2005 3:05 PM