public ActionResult SchoolCompareGet() { ViewBag.tableStatus = "none"; List <SchoolCompare> compare = new List <SchoolCompare>(); SchoolCompare school = new SchoolCompare(); // SchoolC school = new SchoolCompare(); String cs = ConfigurationManager.ConnectionStrings["CEASYS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { try { con.Open(); // Does the connection with databas var selectCommand = "SELECT SchoolId, SchoolName FROM SchoolData"; using (SqlCommand cmd = new SqlCommand(selectCommand, con)) { SqlDataReader result = cmd.ExecuteReader(); if (result.HasRows) { // Read advances to the next row. while (result.Read()) { school.SchoolId = result.GetInt32(result.GetOrdinal("SchoolId")); school.SchoolName = result.GetString(result.GetOrdinal("SchoolName")); compare.Add(new SchoolCompare { SchoolId = school.SchoolId, SchoolName = school.SchoolName }); } // result.NextResult(); } Session["SchoolNames"] = compare; return(View(compare)); } } // end try catch (Exception e) // catches the exception message { ViewBag.SchoolMessage = "School data unavailable" + e; } // end catch finally { con.Close(); //Closes the connection to database } } return(View()); }
public ActionResult SchoolCompareGet(string[] schoolname) { ViewBag.tableStatus = "inline"; SqlDataReader result; List <SchoolCompare> SchoolWholeData = new List <SchoolCompare>(); SchoolCompare s = new SchoolCompare(); String cs = ConfigurationManager.ConnectionStrings["CEASYS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { try { con.Open(); // Does the connection with databas foreach (var item in schoolname) { int schoolid = int.Parse(item); var selectCommand = "SELECT * FROM SchoolData where SchoolId=" + schoolid; using (SqlCommand cmd = new SqlCommand(selectCommand, con)) { result = cmd.ExecuteReader(); if (result.HasRows) { // Read advances to the next row. while (result.Read()) { s.SchoolId = result.GetInt32(result.GetOrdinal("SchoolId")); s.AddressSchool = result.GetString(result.GetOrdinal("AddressSchool")); s.City = result.GetString(result.GetOrdinal("City")); s.SchoolCode = result.GetString(result.GetOrdinal("SchoolCode")); s.WebSite = result.GetString(result.GetOrdinal("WebSite")); s.SchoolType = result.GetString(result.GetOrdinal("SchoolType")); s.TutionFee = result.GetString(result.GetOrdinal("TutionFee")); s.GraduateRate = result.GetString(result.GetOrdinal("GraduateRate")); s.RetentionRate = result.GetString(result.GetOrdinal("RetentionRate")); s.BestProgram = result.GetString(result.GetOrdinal("BestProgram")); s.ReviewLink = result.GetString(result.GetOrdinal("ReviewLink")); s.AcceptanceRate = result.GetString(result.GetOrdinal("AcceptanceRate")); s.Comment = result.GetString(result.GetOrdinal("Comment")); s.EmailAddress = result.GetString(result.GetOrdinal("EmailAddress")); s.CourseAvailable = result.GetString(result.GetOrdinal("CourseAvailable")); s.SchoolName = result.GetString(result.GetOrdinal("SchoolName")); SchoolWholeData.Add(new SchoolCompare { SchoolId = s.SchoolId, AddressSchool = s.AddressSchool, City = s.City, SchoolCode = s.SchoolCode, WebSite = s.WebSite, SchoolType = s.SchoolType, TutionFee = s.TutionFee, GraduateRate = s.GraduateRate, RetentionRate = s.RetentionRate, BestProgram = s.BestProgram, ReviewLink = s.ReviewLink, AcceptanceRate = s.AcceptanceRate, Comment = s.Comment, EmailAddress = s.EmailAddress, CourseAvailable = s.CourseAvailable, SchoolName = s.SchoolName }); // end of Add list } // end while // result.NextResult(); } // end if result.Close(); } // end usisng } //foreach return(View(SchoolWholeData)); } // end try catch (Exception e) // catches the exception message { ViewBag.SchoolMessage = "School data unavailable" + e; } // end catch finally { con.Close(); //Closes the connection to database } // end finally } // end using return(View()); } // end schoolcompareget