[RESOLVED] Not able to delete object from bin
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Not able to delete object from bin

  1. #1
    Join Date
    Sep 2010
    Posts
    26

    [RESOLVED] Not able to delete object from bin

    I have added a 'book' and am trying to delete that book from book.bin. It goes through the code and says it is deleted, but it hasn't actually deleted it from the book.bin file. The delete is based on the ISBN.

    Code:
                    Book book = new Book();
    
                    string InputIsbn = DelISBNTxt.Text;
                    string Btitle = DelTitleTxt.Text;
    
                    BookMgr bookMgr = new BookMgr();
                    bookMgr.DeleteBook(book);
                    Book DBook = bookMgr.DeleteBook(book);
                    string RetIsbn = DBook.isbn;
    
                    if (String.Equals(InputIsbn, RetIsbn))
                    {
                        File.Delete(book);
                        MessageBox.Show(DBook.title + " has been deleted");
                    }
                    else
                        MessageBox.Show(Btitle + " does not exist!");
    Code:
            public Book DeleteBook(Book c) 
            {
                IBookService bookSvc = (IBookService)GetService(typeof(IBookService).Name);
                Book bookD = bookSvc.RetrieveBook();
                return bookD;
            }
    Code:
            public Book RetrieveBook()
            {
                FileStream loadStream = new FileStream("Book.bin", FileMode.Open, FileAccess.Read);
                IFormatter formatter = new BinaryFormatter();
                Book bookX = formatter.Deserialize(loadStream) as Book;
                loadStream.Close();
                return bookX;
            }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,479

    Re: Not able to delete object from bin

    Does book.bin get copied over into the output folder each time you run the program?

  3. #3
    Join Date
    Sep 2010
    Posts
    26

    Re: Not able to delete object from bin

    When I add a book, it will update the Book.bin with what I have added. Just checked though and it appears as though it isnt saving each one, just the last one that I entered. So, will need to look at that part of it. The RetrieveBook only has a loadstream, not a savestream, so maybe that has something to do with it?

  4. #4
    Join Date
    Sep 2010
    Posts
    26

    Re: Not able to delete object from bin

    OK, I got the delete working by adding the CreateBook that has the savestream in it. Now I just have to figure out why it isn't adding each book i enter, instead just overwriting the last with the current entry.
    Last edited by mtn*rain; October 21st, 2010 at 05:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center