always getting a 0 returned using ExecuteScalar (ms datablocks)

  • Thread starter Thread starter Max
  • Start date Start date
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
 
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?
 
In my stored proc I have return @errorcode or return -1

I thought ExecuteScalar was for getting a single value...
 
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
 
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!
 
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
 
Back
Top