//get all the books public List<BookEN> getCookwares() { List<BookEN> books = new List<BookEN>(); String sql = "SELECT * FROM Book"; // string sql = "SELECT * FROM NOTES ORDER BY ID DESC"; SqlConnection con = new SqlConnection(db); try { con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader reader = cmd.ExecuteReader(); BookEN bookTemp = new BookEN(); while (reader.Read()) { bookTemp = new BookEN(); bookTemp.Author = reader["Author"].ToString(); bookTemp.Date = reader["Date"].ToString(); bookTemp.Isbn = reader["Isbn"].ToString(); bookTemp.Title = reader["Title"].ToString(); books.Add(bookTemp); } } catch (Exception ex) { } finally { con.Close(); } return books; }
//Function to add a new book public bool insertBook(BookEN book) { bool added = false; SqlConnection c = new SqlConnection(db); try { c.Open(); SqlCommand com = new SqlCommand("INSERT INTO Book VALUES (" + book.Title + ", " + book.Author + "," + book.Isbn + "," + book.Date + ")", c); com.ExecuteNonQuery(); added = true; } catch (Exception ex) { } finally { c.Close(); } return added; }
public BookEN getBook(RecipeEN recipe) { BookEN book = new BookEN(); SqlConnection c = new SqlConnection(db); try { c.Open(); SqlCommand com = new SqlCommand("SELECT FROM Book WHERE Title = '" + recipe.Book + "'", c); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { book.Author = dr["Author"].ToString(); book.Date = dr["Date"].ToString(); book.Isbn = dr["Isbn"].ToString(); book.Title = dr["Title"].ToString(); } } catch (Exception ex) { } finally { c.Close(); } return book; }
//Function to add a new book public void insertBook(BookEN book) { }
// Get all the books public List<BookEN> getBooks() { BookEN books = new BookEN(); return books.getBooks(); }