Exemplo n.º 1
0
        /// <summary>
        /// this seclests the lectuer from the database 
        /// to be used with in this code and  useing a  seclect  query 
        /// </summary>
        /// <returns>list of lectuerCl</returns>
        public List<LecturerCL> SelectLectuer()
        {
            string query = "SELECT * FROM lecturer";

            // creats a  list  of lectuer objects
            List<LecturerCL> allLect = new List<LecturerCL>();

            //Open connection
            if (this.OpenConnection() == true)
            {
            //Create Command
            MySqlCommand cmd = new MySqlCommand(query, connection);
            //Create a data reader and Execute the command
            MySqlDataReader dataReader = cmd.ExecuteReader();

            //Read the data and store them in the list
            while (dataReader.Read())
            {
                // adds the  data in the columes to the class varbiles and pass them in
                Int32 lectuerID = dataReader.GetInt32(0);
                String lectuerName = dataReader.GetString(1);
                Int32 requiedTeachingHrs = dataReader.GetInt32(2);
                Int32 teachingHrs = dataReader.GetInt32(3);
                // crates the  lectuer object
                LecturerCL l = new LecturerCL(lectuerID, lectuerName,  teachingHrs, requiedTeachingHrs);
                // add all the curent values to the database
                allLect.Add(l);
            }
            //close Data Reader
            dataReader.Close();

            //close Connection
            this.CloseConnection();
            }
            // return all the records in the database for the lecturer
            return allLect;
        }
Exemplo n.º 2
0
        /// <summary>
        /// this method allows a user to insert an lectuer 
        /// infomation into the data base useing a Insert query 
        /// </summary>
        /// <param name="l"></param>
        public void InsertLect(LecturerCL l)
        {
            // query to allow data to be placed into the table lectuere on the database from the lectuerCL class
            string queryLect = "INSERT INTO lecturer (lecturerName, lecturerRequiredHours, lecturerTaughtHours) VALUES('" + l.lectName + "','" + l.ReqTeachingHrs + "','" + l.TeachingHrs + "')";

            //open connection
            if (this.OpenConnection() == true)
            {
            //create command and assign the query and connection from the constructor
            MySqlCommand cmd = new MySqlCommand(queryLect, connection);

            //Execute command
            cmd.ExecuteNonQuery();

            //close connection
            this.CloseConnection();
            }
        }