Help Required in SqlHelper.ExecuteNonQuery

  • Thread starter Thread starter RJN
  • Start date Start date
R

RJN

Hi

I want to get the rerurn value from a stored procedure

My stored proc looks like this

create proc test
.....
if..
return 1
else
if ..
return 2
else
..return 0

I'm using the SqlHelper.ExecuteNonQuery and pass the procedure name,
connection and an array of parameters. How I do I get the return value
from this. If I create a parameter of Diretion ReturnValue and include
in the parameter array, I get an error that the parameters don't match.
WHat is the correct way of doing?

Regards

RJN
 
Hi,

Use ExecuteScalar instead.

http://msdn.microsoft.com/library/d...qlclientsqlcommandclassexecutescalartopic.asp

Ken
-------------------------

Hi

I want to get the rerurn value from a stored procedure

My stored proc looks like this

create proc test
.....
if..
return 1
else
if ..
return 2
else
..return 0

I'm using the SqlHelper.ExecuteNonQuery and pass the procedure name,
connection and an array of parameters. How I do I get the return value
from this. If I create a parameter of Diretion ReturnValue and include
in the parameter array, I get an error that the parameters don't match.
WHat is the correct way of doing?

Regards

RJN
 
Use executeScalar to return a ret val. ExecuteNonQuery would be for
something like "set transaction isolation level read uncommitted" or
similar.

hth
Eric
 
Use executeScalar to return a ret val. ExecuteNonQuery would be for
something like "set transaction isolation level read uncommitted" or
similar.

....or something less exotic like INSERT, UPDATE, or DELETE.
 
Forgot to mention that I'm having update statements in the stored proc
so i can't use ExecuteScalar
 
True, but DML from the front-end is bad practice. Stored procedures should
be the only means of DML.
 

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

Back
Top