ExecuteNonQuery() method will return you number of rows inserted, updated or removed.
To retrieve some value, use a SELECT 'value you want' and you ExecuteScalar() to read it.
All,
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
RETURN (0)
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.
Thanks,
Daz
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try like this
Dim conn As New SqlConnection(ConnectionSt
Dim cmd As New SqlCommand("dbo.FGSRetread
cmd.Parameters.Add(New SqlParameter("@DocketNumbe
Dim retPara As SqlClient.SqlParameter = cmd.Parameters.Add("@retVa
retPara.Direction = ParameterDirection.ReturnV
cmd.CommandType = CommandType.StoredProcedur
conn.Open()
cmd.Connection = conn
cmd.ExecuteNonQuery()
msgbox retPara.value
MsgBox("Completed")
Business Accounts
Answer for Membership
by: reb73Posted on 2009-03-02 at 15:03:01ID: 23779436
You are better off using an output parameter, instead of messing with return values.
Just define an extra parameter in the stored procedure, flagging this as an output with the keyword OUTPUT after the parameter and populate this with different values - e.g. 1 for insert, 0 for update - and then check the value of this parameter in your vb.net code..