Use Output parameter with stored procedure in .net core.

Aman Sharma

If you want to return value from stored procedure, then you can use Output parameter. How to use output parameter in .net core using stored procedure is given below:


In given example, I have used input as well as output parameter. If you want to return string then size of output parameter must be same in .net core and in stored procedure. 




                var Param1= new SqlParameter


                    ParameterName = "InputPrm",

                    DbType = System.Data.DbType.Int32,

                    Direction = System.Data.ParameterDirection.Input,

                    Value= vesselId


                var parameterReturn = new SqlParameter


                    ParameterName = "output",

                    DbType = System.Data.DbType.String,


                    Direction = System.Data.ParameterDirection.Output


                _context.Database.ExecuteSqlCommand("EXEC ProcedureName @ InputPrm, @output OUT", Param1, parameterReturn);


                return (string)parameterReturn.Value;



            catch (Exception ex)


                throw ex;





Post a Comment

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !