CsvReader : How to go to the beginning #2030
Unanswered
sylvaincaillot
asked this question in
Q&A
Replies: 1 comment
-
Have you tried reader.BaseStream.Seek(0, SeekOrigin.Begin); or reader.BaseStream.Position = 0 ? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to do extract the headers of a csv and then load this csv into a datatable and I am struggle with how the memory objects are allocated:
Initially, I have tried
It didn't work for the datatable as the headers row was skipped.
I then tried to add
reader1.BaseStream.Position = 0;
with no effect.I then tried to add a distinct CsvReader for the datatable:
Then I got weird result with CSV1 containing 9 columns while dt1 only contains 4 columns. So again some memory allocations problems.
The only way it works is by adding a distinct StreamReader for the datatable like:
It looks quite counter-productive and memory consuming for such a simple need.
How can I make sure that I go at the beginning of my CsvHeader before filling my datatable?
Beta Was this translation helpful? Give feedback.
All reactions