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:
Great Post!
Thank you
It can help me.
Thank you
Awesome...was exactly what I´m looking for. Thank you!
Hi there to every one, it's really a good for me to visit
this web page, it consists of priceless Information.
Create Access link tables dynamically vbasic programming example