By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,687 Members | 2,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,687 IT Pros & Developers. It's quick & easy.

always getting a 0 returned using ExecuteScalar (ms datablocks)

P: n/a
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.st rConn, _
"gpUpdateMember", _
Convert.ToInt32(lblMember_id.Text), _
-snip-

-Max
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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?
"Max" <no****@notvalid.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
Anyone know why I'm always getting 0 returned? My stored procedure
returns -1.

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

-Max

Nov 18 '05 #2

P: n/a
Max
In my stored proc I have return @errorcode or return -1

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

"Scott M." <s-***@nospam.nospam> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
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?
"Max" <no****@notvalid.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
Anyone know why I'm always getting 0 returned? My stored procedure
returns -1.

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

-Max


Nov 18 '05 #3

P: n/a
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
"Max" <no****@notvalid.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
In my stored proc I have return @errorcode or return -1

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

"Scott M." <s-***@nospam.nospam> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
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?
"Max" <no****@notvalid.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
Anyone know why I'm always getting 0 returned? My stored procedure
returns -1.

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

-Max



Nov 18 '05 #4

P: n/a
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!

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:eb**************@TK2MSFTNGP15.phx.gbl...
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
"Max" <no****@notvalid.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
In my stored proc I have return @errorcode or return -1

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

"Scott M." <s-***@nospam.nospam> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
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?
"Max" <no****@notvalid.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
Anyone know why I'm always getting 0 returned? My stored procedure
returns -1.

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

-Max



Nov 18 '05 #5

P: n/a
You almost got it, just drop the RETURN part

SELECT @errorcode

Greg
"Max" <no****@notvalid.com> wrote in message
news:ei***************@TK2MSFTNGP11.phx.gbl...
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!

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:eb**************@TK2MSFTNGP15.phx.gbl...
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
"Max" <no****@notvalid.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
In my stored proc I have return @errorcode or return -1

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

"Scott M." <s-***@nospam.nospam> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
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?
"Max" <no****@notvalid.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
> Anyone know why I'm always getting 0 returned? My stored procedure
> returns -1.
>
> Dim iErrorCode As Int32
> iErrorCode = Convert.ToInt32(SqlHelper.ExecuteScalar(AppVars.st rConn,
> _
> "gpUpdateMember", _
> Convert.ToInt32(lblMember_id.Text), _
> -snip-
>
> -Max
>



Nov 18 '05 #6

P: n/a
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
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You almost got it, just drop the RETURN part

SELECT @errorcode

Greg
"Max" <no****@notvalid.com> wrote in message
news:ei***************@TK2MSFTNGP11.phx.gbl...
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!

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.