always getting a 0 returned using ExecuteScalar (ms datablocks)

M

Max

Anyone know why I'm always getting 0 returned? My stored procedure
returns -1.

Dim iErrorCode As Int32
iErrorCode = Convert.ToInt32(SqlHelper.ExecuteScalar(AppVars.strConn, _
"gpUpdateMember", _
Convert.ToInt32(lblMember_id.Text), _
-snip-

-Max
 
S

Scott M.

ExecuteScalar: Executes the query, and returns the first column of the
first row in the result set returned by the query. Extra columns or rows are
ignored.

What were you expecting back?
 
M

Max

In my stored proc I have return @errorcode or return -1

I thought ExecuteScalar was for getting a single value...
 
G

Greg Burns

To get a Return value you have to use a parameter...

cmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int).Direction =
ParameterDirection.ReturnValue
....
Dim retval as integer = CInt(cmd.Parameters("RETURN_VALUE").Value)

HTH,
Greg
 
M

Max

Thanks I know that works, but principally speaking I swore I could return a
value with ExecuteScalar. I think it's my return statement in the stored
procedure...

something like...
RETURN SELECT @errorcode
or..
RETURN SELECT myvar = @errorcode

Something that returns a recordset, but it doesn't...

Thanks for your guys help!
 
M

Max

I think you're right! lol! This tells me I need to get a book on tsql
instead of relying on samples and quick start guides.

Thanks!

-Max
 

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

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top