public static String getAverageGradeByMajor(String majorId, String semester, String year) { decimal grade = 0; String cString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString; string getGradeString; getGradeString = "SELECT [dbo].[getGradeAvgByCourse] ( " + majorId + " ,'%" + year + "%' ,'%" + semester + "%')"; using (SqlConnection connection = new SqlConnection(cString)) { SqlCommand command = new SqlCommand(getGradeString, connection); connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { if (!reader.IsDBNull(0)) { grade = reader.GetDecimal(0); } else { grade = -1; } } } connection.Close(); } return(GradeList.convertPointsToGrade((double)grade)); }