Exemplo n.º 1
0
        /*!  \fn void add_book(string sql_statement,Book book)
         * \brief A adding book function.
         * \details It is used to add book value to database.
         * \param sql_statement (string) it holds sql statement.
         * \param book (Book) it holds Book object.
         * \return void
         */
        public void add_book(string sql_statement, Book book)
        {
            using (SQLiteConnection connection = new SQLiteConnection(path))
            {
                SQLiteCommand sql_command = new SQLiteCommand();
                sql_command.CommandText = sql_statement;

                sql_command.Connection = connection;  //bağlantı kuruluyor.
                sql_command.Parameters.AddWithValue("@Id", book.getId());
                sql_command.Parameters.AddWithValue("@Name", book.getName());
                sql_command.Parameters.AddWithValue("@Price", book.getPrice());
                sql_command.Parameters.AddWithValue("@Image", "Book");
                sql_command.Parameters.AddWithValue("@ISBN", book.ISBN);
                sql_command.Parameters.AddWithValue("@Author", book.author);
                sql_command.Parameters.AddWithValue("@Publisher", book.publisher);
                sql_command.Parameters.AddWithValue("@Page", book.page);
                sql_command.Parameters.AddWithValue("@Description", book.Description);
                sql_command.Parameters.AddWithValue("@Stock", book.Stok);
                connection.Open();

                try
                {
                    sql_command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }


                connection.Close();
            }
        }