Since you didn't provide any description of the data you're dealing with, it's hard to come up with anything better than this:
while ((length = Br.Read(rec_arr, (int)0, 1024)) > 0) *
{
// Read other info here
var foo = DecodeLong(rec_arr, 4);
if (foo != 825045041)
Dgv.Rows.Add(foo, count++, DecodeDateTime(rec_arr, 28));
}
And in the To_Fields
method you can just skip one record:
int rec_num_to_read = Dgv.CurrentRow.Index + 1;
However, I tried to run your code with the data from the screenshot, and it didn't work. I skip 1024 bytes (the unwanted record) and what I get from the beginning of the next record doesn't seem to be valid either. The value is 542966816, and the date is just mess. I don't know the date format, but it's clear that there's something wrong.
I don't have enough reputation to post images, so here's a link: http://i.stack.imgur.com/AdIAa.gif
I'd like to add that several statements are useless.
You don't need to call Close()
, that's what using
is for. Explanation on MSDN.
Br.Close();
Fs.Close();
The other remarks are true, if there's no code you have omitted.
Reading is done in a loop, so ReadAllBytes
is not needed.
rec_arr = File.ReadAllBytes(import.FileName);
length
is not used either.
FileInfo fi = new FileInfo(import.FileName);
long length = fi.Length;
And one more thing, long
is 64 bit in C#. Use int
which is 32 bit instead. So it's better to rename DecodeLong
to DecodeInt32
, because it's quite confusing really.