|
-
Sep 27th, 2012, 03:09 AM
#1
Thread Starter
Fanatic Member
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);???
...
}
-
Sep 27th, 2012, 04:23 AM
#2
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.
-
Sep 27th, 2012, 09:18 PM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|