I'm having problem populating a Label with average value from MSSQL database.
The code written in database is this:
ALTER PROCEDURE [dbo].procTakeAverage
(
@ID_Person int
)
AS
BEGIN
SELECT AVG (RATING.Grade) from RATING
inner join SUBJECT on SUBJECT.ID_Subject= RATING.ID_Subject
where RATING.ID_Subject = @ID_Person and RATING.ID_RatingType=1
END
This stored procedure works perfectly and returns the average value.
The problem is how to show this value in a Label using ASP.NET technology (code).
This is what I tried so far.
What I have tried:
<pre><pre lang="c#">
public void AverageValue()
{
string average= String.Empty;
DataTable dt = new DataTable();
SqlConnection sqlConn = new SqlConnection("Here is the string connection");
try
{
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand("procTakeAverage", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@ID_Person", SqlDbType.Int).Value = average;
sqlCmd.Parameters["@ID_Person"].Value = Convert.ToInt32(lblID_Nxenesi.Text);
sqlCmd.ExecuteNonQuery();
average = lblAverage.Text.ToString();
sqlConn.Close();
}
catch { }
}
This code is not showing me the average value in lblAverage.
Thank you in advance for your time.
Cheers.