Arpan Arpan - 23 days ago 12
Vb.net Question

Get value of Output Parameter from stored procedure

I am trying to get the output parameter from the stored procedure wrote by my Database admin. Here is the stored procedure.

ALTER PROCEDURE [dbo].[sb_AddStudent]
-- Add the parameters for the stored procedure here

@FirstName varchar(25),
@LastName varchar(25),
@Address varchar(300),
@SID int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
BEGIN TRANSACTION

INSERT INTO StudentMaster(EntryDate, FirstName, LastName)
VALUES (getdate(), @FirstName , @LastName);
IF @@ERROR <> 0
GOTO ErrorHandler;

SELECT @SID= max(SID)
FROM StudentMaster

COMMIT TRANSACTION
RETURN 0;


-- if there is an error after any insert/update statement, it will go here --
ErrorHandler:
ROLLBACK TRANSACTION;
RETURN @@error;
END


Here is my code behind in vb.net. I am using Entity Framework.

Dim outputParameter As Entity.Core.Objects.ObjectParameter = New Entity.Core.Objects.ObjectParameter("SID ", GetType(Integer))

db.sb_AddStudent(FirstName, LastNmae, Address, outputParameter)

dim SID = outputParameter.Value


i am not getting any error and data are saved into database but i dont know whats the right way to get the output value from the stored procedure. Please suggest the best way to get the output parameter value.

Answer Source

Deleting Stored procedure form EF and re-adding it to the project fixed the issue for me.