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.
try { 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,
Size=200,
Direction = System.Data.ParameterDirection.Output
};
_context.Database.ExecuteSqlCommand("EXEC ProcedureName @ InputPrm,
@output OUT", Param1, parameterReturn);
return
(string)parameterReturn.Value;
} catch (Exception ex) {
throw
ex; } }
|