public ActionResult CoursesReport4(int id) { var data = db.GetCourseReport(id).First(); ViewBag.SQL = sb.ToString(); return(View(data)); }
//這邊要加入預存程序! //CREATE PROCEDURE[dbo].[GetCourseReport] // @CourseID int // AS //SELECT // Course.CourseID, // Course.Title AS CourseName, // (SELECT COUNT(CourseID) FROM CourseInstructor WHERE (CourseID = Course.CourseID)) AS TeacherCount, // (SELECT COUNT(CourseID) FROM Enrollment WHERE(Course.CourseID = Enrollment.CourseID)) AS StudentCount, // (SELECT AVG(Cast(Grade as Float)) FROM Enrollment WHERE(Course.CourseID = Enrollment.CourseID)) AS AvgGrade //FROM Course //WHERE Course.CourseID=@CourseID public ActionResult CoursesReport4(int?id) { if (!id.HasValue) { return(RedirectToAction("CoursesReport1")); } var data = db.GetCourseReport(id); ViewBag.SQL = sb.ToString(); return(View(data)); }