Ejemplo n.º 1
0
        /**
         *\brief A function to get the music CD list
         *\return The music CD list
         */
        public static List <MusicCD> GetMusicCDList()
        {
            SqlCommand     sqlSelectCommand = MusicCD.GetSelectCommand();
            List <MusicCD> MusicCDList      = new List <MusicCD>();

            try
            {
                DatabaseHandler.SQL_CONNECTION.Open();

                SqlDataReader reader = sqlSelectCommand.ExecuteReader();
                while (reader.HasRows && reader.Read())
                {
                    object[] attributesOfMagazine = new object[5];      //  MusicCD class has 5 attributes.
                    reader.GetValues(attributesOfMagazine);             //  Get the first row.

                    MusicCD newMusicCD = new MusicCD(0, "a", 0);
                    newMusicCD.Fill(attributesOfMagazine);
                    MusicCDList.Add(newMusicCD);
                }

                DatabaseHandler.SQL_CONNECTION.Close();

                return(MusicCDList);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /*  DATA ADAPTER    &&      DATA SET    */

        /**
         *\brief A function to get the SQL data adapter for the given table name
         *\param sourceTableName: Name of the source table
         *\return The SQL data adapter
         */
        public static SqlDataAdapter GetDataAdapterFor(string sourceTableName)
        {
            if (sourceTableName == "tblCustomer")
            {
                return(new SqlDataAdapter(Customer.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING));
            }

            if (sourceTableName == "tblBook")
            {
                return(new SqlDataAdapter(Book.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING));
            }

            if (sourceTableName == "tblMagazine")
            {
                return(new SqlDataAdapter(Magazine.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING));
            }

            if (sourceTableName == "tblMusicCD")
            {
                return(new SqlDataAdapter(MusicCD.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING));
            }

            return(null);
        }