I have a stored procedure and the result I wanted displayed on a page. The problem is that the result will not be stored as it is dynamic but calculated and displayed everytime page load and I don't know how to do that.
CREATE PROCEDURE [dbo].[NivelGlobalRisc]
AS
DECLARE @result decimal(6,2),@ActivitateNGR decimal(6,2),@ZonaLucruNGR decimal(6,2),@CaracterSpecialNGR decimal(6,2)
SET @ActivitateNGR = (SELECT CONVERT(decimal(4,2), Sum(NivelRisc))/CONVERT(decimal(4,2), Count(NivelRisc)) FROM tblActivitate)
SET @ZonaLucruNGR = (SELECT CONVERT(decimal(4,2), Sum(NivelRisc))/CONVERT(decimal(4,2), Count(NivelRisc)) FROM tblZonaLucru)
SET @CaracterSpecialNGR = (SELECT CONVERT(decimal(4,2), Sum(NivelRisc))/CONVERT(decimal(4,2), Count(NivelRisc)) FROM tblCaracterSpecial)
SET @result = (@ActivitateNGR + @ZonaLucruNGR + @CaracterSpecialNGR)/3;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
GetNGR();
}
protected void GetNGR()
{
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand cmd = new SqlCommand("NivelGlobalRisc", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
txtNGR.Text = rdr["@result"].ToString();
}
conn.Close();
}
}
}
How it should be done, please?

Amit MohantyPosted Jan 2, 2024, 2:08 PM
To use output parameter modify your procesude as below
Without optput parameter you can use like this
Jignesh KumarPosted Jan 2, 2024, 2:28 PM
Oh I missed this, you did not select value after set in @result variable. You need to select @result at last o fyour
Marius VasilePosted Jan 2, 2024, 1:56 PM
Ok, after studying more I found a possible solution using output parameters and change code behind with
error message is "ErrorOccured: Procedure NivelGlobalRisc has no parameters and arguments were supplied."
Marius VasilePosted Jan 2, 2024, 1:35 PM
Thank you Jignesh but I have no result displayed either
Jignesh KumarPosted Jan 2, 2024, 1:29 PM