SQLHeper ExecuteNonQuery - returning values

  • Thread starter Thread starter Paul Aspinall
  • Start date Start date
P

Paul Aspinall

Hi
I have a Stored Proc in SQL server, which creates a record key when a record
is created.

I want to return the value back to my code, once the record has been
created.

I am using SQLHelper (Data Application Blocks for SQLServer), and calling
the ExecuteNonQuery method in the SQLHelper class...

Does anyone have any sample code from their C# code, or T-SQL code to help??

Thanks


Paul
 
Hi,

if you use ExecuteNonQuery, the way to return values is within output
parameters. In SQL documentation there are lots of about output parameters
however basically it is a proc parameter specified with OUTPUT keyword. For
example

CREATE PPROCEDURE myProc
....
@newid int OUTPUT
AS
....
/* set the value of the parameter somewhere here */

After the call to ExecuteNonQuery, this value is readable from the
SqlParameter given to the proc (which matches the @newid )
 
Hi - Thanks for the reply.

I am familiar with output parameters from T-SQL, however, I cannot seem to
return values specifically using the SQL Application Blocks (SQLHelper).

Does SQLHelper support output params?

Thanks
 
try using the ExecuteScalar instead this is design to return a single value
from a database call

HTH

Ollie Riches
 
Yes it does, if you declare parameter objects for it explictly. Have you
tried this?
 
Paul,

For SqlHelper.ExecuteNonQuery you need to first define your output
parameters in .NET, call .ExecuteNonQuery (passing it the parameter object),
then reference the .Value of the parameter after your stored procedure
executes.

Let me know if you need code posted.

Paul
 
Back
Top