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
 


5 comments:

fabio said...

Great Post!
Thank you

Anonymous said...

It can help me.
Thank you

Anonymous said...

Awesome...was exactly what I´m looking for. Thank you!

Anonymous said...

Hi there to every one, it's really a good for me to visit
this web page, it consists of priceless Information.

xcod4r said...

Create Access link tables dynamically vbasic programming example

Leave a Reply