Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 how to capture stored proc return value

Author  Topic 

btayfun
Starting Member

2 Posts

Posted - 2005-06-23 : 12:21:36
hello everybody,

i wrote the following stored proc:
CREATE PROCEDURE [SerialNoExists]
(@SerialNo nvarchar(64))
AS

If Exists(Select Serial_No From ITEM Where Serial_No=@SerialNo)

Return -1

Else
Return 0
GO

what i am asking is how will i capture the return value in vb.net?

thanks for any reply :)

jhermiz

3564 Posts

Posted - 2005-06-23 : 13:15:20
You use the sqlcommand object and you add a paramter as a return value (output parameter).


Dim conMyData As SqlConnection
Dim cmdInsert As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intResult As Long

Try
conMyData = New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
cmdInsert = New SqlCommand("insert_blah", conMyData)

With cmdInsert
.CommandType = CommandType.StoredProcedure
parmReturnValue = .Parameters.Add("RETURN_VALUE", SqlDbType.BigInt)
parmReturnValue.Direction = ParameterDirection.ReturnValue
'add the parameters
.Parameters.Add("@ClientID", SqlDbType.Int).Value = Me.ddlClient.SelectedItem.Value
conMyData.Open()
.ExecuteNonQuery()
intResult = CType(.Parameters("RETURN_VALUE").Value, Long)
End With
Catch e As Exception
Response.Write("An Error Occurred: " & e.ToString())
InsertTicket = 0
'clean up and close resources
Finally
cmdInsert = Nothing
conMyData.Close()
conMyData = Nothing
End Try



Jon


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-06-30 : 21:16:26
Hi I also have same problem.
But from my code i am calling stored procedure using exec command.

Can i do this "declare @return_value int; exec @return_value=procname;select @return_value"?

it is just guess. i am not sure how i can bundle multiple statements from .net code.

any help will be great!

Thanks

mk_garg
Go to Top of Page
   

- Advertisement -