コード例 #1
0
        //adding courses
        public int Addcourses(subject subject)
        {
            open();
            string     query = "Insert into subject(course) values('" + subject.subjectname + "')";
            SqlCommand cmd   = new SqlCommand(query, con);
            var        res   = cmd.ExecuteNonQuery();

            close();

            return(res);
        }
コード例 #2
0
        public IEnumerable <subject> Listcourses()
        {
            open();
            string         query   = "select * from course";
            List <subject> courses = new List <subject>();
            SqlCommand     cmd     = new SqlCommand(query, con);

            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    var course = new subject {
                        subjectid = dr.GetInt32(0), subjectname = dr.GetString(1)
                    };
                    courses.Add(course);
                }
            }
            return(courses);

            close();
        }