-
October 21st, 2010, 03:00 PM
#1
[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;
}
-
October 21st, 2010, 04:17 PM
#2
Re: Not able to delete object from bin
Does book.bin get copied over into the output folder each time you run the program?
-
October 21st, 2010, 04:22 PM
#3
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?
-
October 21st, 2010, 04:33 PM
#4
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 04: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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|