Avatar of yo_daz_uk

asked on 

.Net get Return Value from SQL stored procedure


I have a stored procedure that either Inserts or updates a table based on whether it exists or not.  I call the stored procedure from a vb.net program see code below.

What i want to do now is add a return value in the stored procedure to tell me whether it has inserted or updated, and capture that return value in the .net code so i can do some processing on it.

I was thinking adding after the insert statement in the stored procedure

and RETURN(99) for the Update procedure.

All this code compiles however what i want to be able to do is pick up the return code in the .net program.  I do not know how to do it.  So my question is how do i do this?

I'm thinking something like

dim result as integer = cmd.executeNonQuery

However this does not work, i'm guessing because it is executing a none query.

Any help is gratefully appreciated.


Dim conn As New SqlConnection(ConnectionString)
            Dim cmd As New SqlCommand("dbo.FGSRetreadTyre")
            cmd.Parameters.Add(New SqlParameter("@DocketNumber", DocketNumber))
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = conn

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon