473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do i retrieve a Return Value (0 or 1) from my stored proc?

Hi there,
I have a storec proc that schedules a Sql job and finally it returns
0 then it was successfull and if it returns 1 then its unsuccessful.
Now when i run the stored proc in the query analyzer its returning

SQLServerAgent is not currently running so it cannot be notified of
this action.
Stored Procedure: aisinspect.dbo.SP_ChangeInspectionDateNew
Return Code = 0

So in my code behind page i am trying to retrieve the restult with the
below line of code.

Result = cmd.ExecuteScalar.ToString

But its throwing "Object reference not set to an instance of an
object."

I know that ExectureSclara returns the first row first column value.
But my stored proc doesn't return as a row column result its simply
displyaing the above text.
So i am just wondering any other method of cmd object that return the
above sort of values? or i do need to change my stored proc just to
return the result in a row (either 0 or 1) so that i can use
Executescalar in my codebehind page?

Thanks
-L

Dec 21 '05 #1
4 3034
If you are using hte return keyword in in sproc, executeScalar won't work.
Try SELECT 1 and SELECT 0

also is ExecuteScalar() not ExecuteScalar (paranthesis)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Learner" <pr****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi there,
I have a storec proc that schedules a Sql job and finally it returns
0 then it was successfull and if it returns 1 then its unsuccessful.
Now when i run the stored proc in the query analyzer its returning

SQLServerAgent is not currently running so it cannot be notified of
this action.
Stored Procedure: aisinspect.dbo.SP_ChangeInspectionDateNew
Return Code = 0

So in my code behind page i am trying to retrieve the restult with the
below line of code.

Result = cmd.ExecuteScalar.ToString

But its throwing "Object reference not set to an instance of an
object."

I know that ExectureSclara returns the first row first column value.
But my stored proc doesn't return as a row column result its simply
displyaing the above text.
So i am just wondering any other method of cmd object that return the
above sort of values? or i do need to change my stored proc just to
return the result in a row (either 0 or 1) so that i can use
Executescalar in my codebehind page?

Thanks
-L

Dec 21 '05 #2
If you are using return on the SP use:

SqlParameter ret = new SqlParameter("@RETURN_VALUE", returnValue);
ret.Direction = ParameterDirection.ReturnValue;
cmd.Parameteres.Add(ret);

// Get Data from Database
int numRows = cmd.ExecuteNonQuery();

this._id = int.Parse(ret.Value.ToString());
Dec 21 '05 #3
the retun value comes back as a parameter

try:

SqlParameter returnValue = new
SqlParameter("retuenValue",SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(returnValue)
cmd.ExecuteNonQuery();

int theReturnValue = (int) returnValue.Value;

or change your sql to

set nocount on
declare @r int
exec @r = myproc
select @r as returnValue

than executescaler will work
-- bruce (sqlwork.com)

"Learner" <pr****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi there,
I have a storec proc that schedules a Sql job and finally it returns
0 then it was successfull and if it returns 1 then its unsuccessful.
Now when i run the stored proc in the query analyzer its returning

SQLServerAgent is not currently running so it cannot be notified of
this action.
Stored Procedure: aisinspect.dbo.SP_ChangeInspectionDateNew
Return Code = 0

So in my code behind page i am trying to retrieve the restult with the
below line of code.

Result = cmd.ExecuteScalar.ToString

But its throwing "Object reference not set to an instance of an
object."

I know that ExectureSclara returns the first row first column value.
But my stored proc doesn't return as a row column result its simply
displyaing the above text.
So i am just wondering any other method of cmd object that return the
above sort of values? or i do need to change my stored proc just to
return the result in a row (either 0 or 1) so that i can use
Executescalar in my codebehind page?

Thanks
-L

Dec 21 '05 #4
Hello there,

You can do one thing design stored procedure with one out parameter.
Then in that procedure you assign your result.
From your asp.net code execute that procedure before executeNonQuery

define a parameter with out property.
Then executeNonQuery
Then retrive value of parameter.

B

Dec 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Benoist LUGNIER | last post by:
Hello VB .NET - ADO .NET - SQL Server (MSDE) I want to retrieve the parameters of a stored procedure before execute it. I've already try the fillschema but it return the "return object (table)"...
1
by: Dave McKie | last post by:
Hi all, Need some help again. I am trying to retrieve an output from a Stored Procedure...not having much luck. If anyone could steer me in the right direction, it would be appreciated. I'm...
0
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot...
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
8
by: jbonifacejr | last post by:
Hi. I'm sorry to bother all of you, but I have spent two days looking at code samples all over the internet, and I can not get a single one of them to work for me. I am simply trying to get a value...
1
by: Eric Effer | last post by:
Hi I am a newbie with vb.net. I am working with vb.net 2.0 and sql server 2005. I am trying to get the return value from my insert stored proc.Does anyone know how to do this? thanks E
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
2
by: Mick Walker | last post by:
Public Sub CheckProduct(ByVal _ConnString As String, ByVal ProductList As List(Of Import_ImportLines.Lines)) Dim ReturnValue As Integer = 0 ' Our Return Value Dim conn As New SqlConnection Dim...
8
by: colmkav | last post by:
Can someone tell me how I can access the return value of a function called from Oracle as opposed to a store proc from oracle? my oracle function is get_num_dates_varposfile. I am only used to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.