Esempio n. 1
0
        /**
         *\brief A function to get the book list
         *\return The book list
         */
        public static List <Book> GetBookList()
        {
            SqlCommand  sqlSelectCommand = Book.GetSelectCommand();
            List <Book> BookList         = new List <Book>();

            try
            {
                DatabaseHandler.SQL_CONNECTION.Open();

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

                    Book newBook = new Book(0, "a", 0);
                    newBook.Fill(attributesOfBook);
                    BookList.Add(newBook);
                }

                DatabaseHandler.SQL_CONNECTION.Close();

                return(BookList);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
                return(null);
            }
        }
Esempio 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);
        }