How do I use the return value from a SQL stored procedure?

I want to be able to use the returned number to set a Label accordingly.

Something like this:

if the return value == 1 then Label1.Text = "Correct" else Label1.Text = "Wrong"

 

What is the correct syntax for this?  I couldn't find this answer.

0
ChangStaRR
8/11/2008 1:50:33 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

2 Replies
574 Views

Similar Articles

[PageSpeed] 3

If you've just got one return parameter, I usually stick with ExecuteScalar. This will execute a stored procedure and return an object, which is taken from the first row and first column of whatever the stored procedure returns.

So at the end of the stored procedure, after doing what you need to do, add a select statement that either returns 0 or 1.

Then when you use Command.ExecuteScalar(), you'll get an object back that you can cast to a Boolean value.


My code doesn't have bugs, it just develops random features.
0
Matt
8/11/2008 2:01:22 PM

Hi,

Please refer to the following code below for  "get the value from the procedure".

        Dim myConn As New SqlConnection("server=.;database=Test;Uid=sa;Pwd=issac")
        Dim myCommand As New SqlClient.SqlCommand("TestPPP", myConn)
        myConn.Open()
        With myCommand
            .CommandType = CommandType.StoredProcedure
            .Parameters.Add("@id", SqlDbType.VarChar, 20).Value = "value"
            .Parameters.Add("@count", SqlDbType.VarChar, 20).Direction = ParameterDirection.Output
            Try
                .ExecuteNonQuery()
                If .Parameters(1).Value() = "1" Then
                    Label1.Text = "Correct"
                Else
                    Label1.Text = "Wrong"
                End If


            Catch ex As Exception

            End Try
        End With
        myConn.Close()

If I misunderstood the problem, please inform of me.


Sincerely,
Zong-Qing Li
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
0
Zong
8/13/2008 6:01:49 AM
Reply:

Similar Artilces:

How to Retrive the store procedure return value in Ado.Net by using Dot Net?
Hi i am thiru. i try to create the small search engine. so that i have wrote the store procedure for it. thats given below.Create procedure FindtestThree @Name varchar(25), @Location varchar(25), @EmpId varchar(25) as select * from TbInfo where Name like + '%' + @Name + '%' select * from TbInfo where Location like + '%' + @Location + '%' select * from hi where ComName like + '%' + @EmpId + '%' Exec FindtestThree 'aa','a','d' ----------------------------------------- The above procedure return t...

Return Value when using CLR stored procedure. (Edit: For use in SQL side paging)
I have a stored procedure that I put together using the CLR.  The basic idea is the have a query that can accept any number of values.  I havent included the portion of the code that handles smalldatetime searches and I havent yet finished the logic to handle sql data type constraints but I have been working on paging using SQL's Row_Number().  The code below works but I havent been able to come up with a way to find out either how many pages the result set has or how many total rows in the result set.  I thought there might be a way to use a procedure's Return Va...

How to get the return value when using a TableAdapter access a Stored Procedure
I have a Stored Procedure CREATE PROCEDURE test AS BEGIN SELECT Count(*) FROM dbo.test END I can using the unbox get the return value but if i direct return a value form a Stored Procedure like this CREATE PROCEDURE test AS BEGIN return 100 END I can not get the VALUE I do not know how to Please Help Me thx Hi, and welcome to the ASP.NET forums. You can use a SqlParameter with Direction set to ParameterDirection.ReturnValue. Please take a look at this little code sample. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non w...

How to get the return value when using a TableAdapter access a Stored Procedure #2
I have a Stored Procedure CREATE PROCEDURE test AS BEGIN SELECT Count(*) FROM dbo.test END I can using the unbox get the return value but if i direct return a value form a Stored Procedure like this CREATE PROCEDURE test AS BEGIN return 100 END I can not get the VALUE I do not know how to Please Help Me thx You can use such T-SQL statements to get the result from the stored procedure in SQL Server: declare @s intexec @s=testselect @sWelcome to my SQL/ASPNET forum for Chinese http://51up.org/bbs/forumdisplay.php?fid=38...

sql stored procedure
I have stored procedure which contains follwing part of it. it says syntax when i worte line to get @@identity valuewhen delete that  line command succesful. but i need to get @@identity from the insert statement and assign it to a variable and use it after any body pls tell me how to get this within a stored prosedure or what is the error of the following code bit.  (#tblSalesOrders is a temporary table which containsset of  records from orginal table )DECLARE @soNo1 INT  DECLARE @CursorOrders CURSOR SET @CursorOrders = CURSOR FAST_FORWARD...

How to get comma seperated value from sql 2000 database using store procedure
Hi I have two table in database. I m using sql 2000 database..one is user and another is useraccess level table..Useraccess table i m storing userid and accesslever. User Table userid username userfirstname.......1        abc           steve2        xyz           paula3        pqr           Haian   Useraccess Table Userid &n...

How to get comma seperated value from sql 2000 database using store procedure
How to get comma seperated value from sql 2000 database using store procedure  Hi I have two table in database. I m using sql 2000 database..one is user and another is useraccess level table..Useraccess table i m storing userid and accesslever. User Table userid username userfirstname.......1        abc           steve2        xyz           paula3        pqr    ...

I can't get the return value from a Stored Procedure using a DAL and BLL
HI All: I can't get the return value from a Stored Procedure using a DAL and BLL. I created a DAL with a method that call a Stored procedure that insert a row and return 1 if was succefully and 0 if not. Then I created a BLL that call the DAL method but I can't get the return value.   [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)] public Object NewCountry(int CountryId, string CountryName, string Abbrev, string UserId) { Int obj; obj = Adapter.NewCountry(CountryId, CountryName, Abbrev, UserId); return obj; } Can...

How to get return value or output value from stored procedure with sqldatasource control?
I created a user registration web page with sqldatasource, some textbox controls or submit button web control, I applied below stored procedure in insert command of sqldatasource control, but how can I get return value from stored procedure after clicking submit button, I want to judge whether data has been saved into database by return value, then give user a message. Who can tell me? thanks much. ALTER PROCEDURE UserInsert ( @Email nvarchar(50), @Password nvarchar(50), @FullName nvarchar(50), @Phone nvarchar(50), @Mobile nvarchar(50), @Address nvarchar(100), ...

How to transfer a GUID created using vb.net into a SQL database using a stored procedure
I am able to create a guid using: Public Function GetGUID() As String ' Returns a new GUID Return System.Guid.NewGuid.ToString End Function however when I try to add this to a parameter using the following: Me.cmdSpAddOptions.Parameters("@QuoteDetailID").Value = GetGUID() I get an error, I have also tried this: Dim uidQuoteDetail As String = GetGUID() Dim myuid = New System.Guid(uidQuoteDetail) Me.cmdSpAddOptions.Parameters("@QuoteDetailID").Value = myuid but get the error "Object must implement IConvertible" A...

sql count using stored procedure withing stored procedure
I have a stored procedure that among other things needs to get a total of hours worked. These hours are totaled by another stored procedure already. I would like to call the totaling stored procedure once for each user which required a loop sort of thing for each user name in a temporary table (already done) total = result from execute totaling stored procedure Can you help with this Thanks It would be easier if you can change the stored procedure into a function. Once you do that, the total can be calculated easily with something like thisSelect Sum(dbo.CalculateHours(User...

How to get return value from stored procedure ?
Hello I am calling a stored procedure in ASE 11.9.2 using the correct syntax with the default SQLCA transaction object DECLARE reverse_all PROCEDURE FOR @rv = dbo.sp_reverse_decision @ord = :order_number, @osn = :order_service_number; EXECUTE reverse_all; How can I obtain the return value of @rv in Powerbuilder ? Do I have to use an additional parameter with the OUT keyword ? The procedure call is working and the value of sqlcode is zero but I need to know the return value. Many thanks Alan. Alan, Try defining your stored procedure as a lo...

Use Resultset Returned from a Stored Procedure in another Stored Procedure
I have a store procedure (e.g. sp_FetchOpenItems) in which I would like to call an existing stored procedure (e.g. sp_FetchAnalysts). The stored proc, sp_FetchAnalysts returns a resultset of all analysts in the system. I would like to call sp_FetchAnalysts from within sp_FetchOpenItems and insert the resultset from sp_FetchAnalysts into a local temporary table. Is this possible?  Thanks, Kevin Yes you do that with sp_executesql that is covered in the first link and if you need temp tables the second link covers some tricks of how to use them.  Hope this helps. http://support...

Using a Stored Procedure to query other stored procedures and then return the results
Seems like I'm stealing all the threads here, :\ But I need to learn :) I have a StoredProcedure that needs to return values that other StoredProcedures return.Rather than have my DataAccess layer access the DB multiple times, I would like to call One stored Procedure, and have that stored procedure call the others to get the information I need. I think this way would be more efficient than accessing the DB  multiple times. One of my SP is:SELECT I.ItemDetailID, I.ItemDetailStatusID, I.ItemDetailTypeID, I.Archived,     I.Expired, I.ExpireDate, I.Deleted, S.N...

Web resources about - How do I use the return value from a SQL stored procedure? - asp.net.getting-started

Parliamentary procedure - Wikipedia, the free encyclopedia
... of the House of Commons of the Parliament of the United Kingdom , from which it derives its name. In the United States, parliamentary procedure ...

Procedure is more a snap than a snip
A QUEENSLAND doctor is bidding to set an unusual world record by performing the highest number of vasectomies in one day, with the help of fellow ...

Rushed cosmetic procedures a 'recipe for disaster'
​When Chanelle O'Hare went searching online for a deal on potential cosmetic procedures, she could not have imagined that what she ended ...

Jetstar procedures under investigation after planes took off too heavy
Jetstar's procedures for calculating the weight of its aircraft are under review by the Australian Transport Safety Bureau after two of its planes ...

Old Lady Lawyer: Uncivil Procedure
What is some of the worst behavior you've witnesses by attorneys?

NFL Announces Changes to Officiating Procedures for Playoffs - Bleacher Report
The NFL formally approved changes to its postseason officiating procedures to allow referees the opportunity to consult Vice President of Officiating ...

We need to reform the culture of law enforcement, not just the procedures
We need to reform the culture of law enforcement, not just the procedures by digby I have a new piece up at Salon this morning about police ...

Will Paul Ryan Make His Mark As Speaker By Instituting Impeachment Procedures Against President Obama ...
Wisconsin Ayn Rand devotee Paul Ryan just started his new job as Speaker of the dysfunctional House Republicans. And he's already headed for ...

TSA Updates Screening Procedure, Will Mandate Some Passengers Use Full-Body Scanners
... Imaging Technologies, or AIT, in favor of full-body pat-downs by TSA agents. Under the new mandate, not everyone can opt for the pat-down procedure. ...

'Painless' dental cavity procedure regrows tooth enamel
... "cavity" a lot of people sweat thinking about painful injections and relentless drilling. But scientists in Britain have developed a new procedure ...

Resources last updated: 1/6/2016 12:14:28 PM