SQLHeper ExecuteNonQuery - returning values

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
 
T

Teemu Keiski

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 )
 
P

Paul Aspinall

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
 
O

Ollie Riches

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

HTH

Ollie Riches
 
T

Teemu Keiski

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

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top