Showing posts with label stored procedure. Show all posts
Showing posts with label stored procedure. Show all posts
    5 comments
This Post Shows how we can Return Values From a Stored Procedure

First off, your stored procedure will look like this ...



CREATE PROC SomeSproc AS INSERT INTO MyTable (fieldName) VALUES ('MyValue') RETURN @@IDENTITY 

Here is some sample code that will grab that return value ...

Dim con As New SqlConnection("connectString ...")
Dim cmd As New SqlCommand("SomeSproc", con)
Dim prm As New SqlParameter("RETURN", SqlDbType.Int)
Dim recordId As Integer
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(prm)
prm.Direction = ParameterDirection.ReturnValue

Try
    con.Open()
    cmd.ExecuteNonQuery()
    recordId = CType(prm.Value, Integer)
Finally
    If con.State = ConnectionState.Open Then
        con.Close()
    End If
End Try
 


Read More [...]