Beispiel #1
0
        public static List <Enrolment> getCourses(String program, String semester, String Ptype)
        {
            List <Enrolment> offerList  = new List <Enrolment>();
            String           connStr    = "data source= LocalHost;Initial Catalog=Unknown;  integrated security = true";
            SqlConnection    dbConn     = new SqlConnection(connStr);
            SqlCommand       sqlStmt    = new SqlCommand("SELECT  progCode, semCode, type, code, name FROM CourseOffer, Course WHERE Course.courseCode = CourseOffer.code AND  @pCode = progCode AND @type=type AND @sCode= semCode", dbConn);
            SqlParameter     parameter  = new SqlParameter("@pCode", program);
            SqlParameter     parameter2 = new SqlParameter("@sCode", semester);
            SqlParameter     parameter3 = new SqlParameter("@type", Ptype);

            sqlStmt.Parameters.Add(parameter);
            sqlStmt.Parameters.Add(parameter3);
            sqlStmt.Parameters.Add(parameter2);
            SqlDataReader reader = null;

            try
            {
                dbConn.Open();
                reader = sqlStmt.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        reader.Read();
                        String    progCode = reader.GetString(0);
                        String    semCode  = reader.GetString(1);
                        String    type     = reader.GetString(2);
                        String    code     = reader.GetString(3);
                        String    name     = reader.GetString(4);
                        Enrolment course   = new Enrolment(progCode, semCode, type, code, name);
                        offerList.Add(course);
                    }
                }
            }
            catch (SqlException error)
            {
                Console.WriteLine(error.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (dbConn != null)
                {
                    dbConn.Close();
                }
            }
            return(offerList);
        }