Results 1 to 3 of 3

Thread: Delete records in binary file?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    522

    Delete records in binary file?

    suppose I have the code was inserting records into the file c: \ \ test.dat see the code http://www.koders.com/csharp/fid4FB0...D1D0C61.aspx?s = CDEF% 3Afile

    ith now want to delete the records in the file c: \ \ test.dat I can copy the code
    btnAppend_Click to delete sample letter how i
    code:


    'Add items
    private void btnAppend_Click (object sender, System.EventArgs e)
    {
    ....
    sf.Open (System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.None);???
    ...

    }
    'Delete the ith sample
    private void btnDelete_Click (object sender, System.EventArgs e)
    {
    ....
    sf.Open (System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.None);???
    ...

    }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Delete records in binary file?

    You can't just delete a record in a binary file. The file is the size it is and you can't simply remove bytes from the middle. Appending is different because that's adding bytes to the end. If you want to delete a record then you can do one of two things:

    1. Logically delete the file, which would involve setting a flag in the record to indicate that it was no longer a valid record. In that case no records would ever actually be removed from the file, which might be a problem if you add and delete a lot of records. The file might end up being large and primarily contain obsolete data.

    2. Physically delete the record, which would involve reading in all the data, removing the record to delete, then writing out all the data again.

    This is an example of why, for all but the simplest scenarios, databases are preferred to structured data files.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    522

    Re: Delete records in binary file?

    have you got for example ? add, delete, edit, ... struct binary record form and load the data into the listview? I'm using C # 2005, if you share yourself with, thank you

Posting Permissions

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



Click Here to Expand Forum to Full Width