Exemple #1
0
        public static BookEntity GetByTitle(string title)
        {
            BookEntity book = new BookEntity();

            string commandtext = "SELECT * FROM books WHERE title = @title";

            OleDbCommand command = new OleDbCommand(commandtext, connenction);

            command.Parameters.AddWithValue("@title", title);

            try
            {
                connenction.Open();
                OleDbDataReader dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    book.ID     = dataReader["id"].ToString();
                    book.Title  = dataReader["title"].ToString();
                    book.Author = dataReader["author"].ToString();
                    book.Price  = dataReader["price"].ToString();
                    book.ISBN   = dataReader["isbn"].ToString();
                }
                dataReader.Close();
            }

            catch (Exception e)
            { }

            finally
            {
                connenction.Close();
            }

            return(book);
        }
Exemple #2
0
        public static List <BookEntity> GetAll()
        {
            List <BookEntity> bookCollection = new List <BookEntity>();

            string commandtext = "SELECT * FROM books";

            OleDbCommand command = new OleDbCommand(commandtext, connenction);

            try
            {
                connenction.Open();
                OleDbDataReader dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    //making a new book entity for every record in the DB
                    BookEntity book = new BookEntity();
                    book.ID     = dataReader["ID"].ToString();
                    book.Title  = dataReader["title"].ToString();
                    book.Author = dataReader["author"].ToString();
                    book.Price  = dataReader["price"].ToString();
                    book.ISBN   = dataReader["isbn"].ToString();

                    bookCollection.Add(book);
                }
                dataReader.Close();
            }

            catch (Exception e)
            { }

            finally
            {
                connenction.Close();
            }

            return(bookCollection);
        }
Exemple #3
0
        private void PopulateTextboxes()
        {
            BookEntity book = new BookEntity();

            book = BookController.GetByTitle(tb_input.Text);

            if (book.Title != null)
            {
                parameters.Add("id", book.ID);
                tb_title.Text  = book.Title;
                tb_author.Text = book.Author;
                tb_price.Text  = book.Price;
                tb_isbn.Text   = book.ISBN;

                tb_title.Visible  = true;
                tb_price.Visible  = true;
                tb_author.Visible = true;
                tb_isbn.Visible   = true;
            }
            else
            {
                MessageBox.Show("No records match the input criteria.", "Information");
            }
        }