Read only first line in CSV

13 views
Skip to first unread message

David

unread,
Dec 2, 2009, 9:39:32 PM12/2/09
to CSVChat
I need to read only the first row in the CSV (Header Row), then I can
use the column headers to build a create table SQL statement to create
the table in my database.

How can I read only the first line and display it on my web
application?

shriop

unread,
Dec 2, 2009, 10:39:42 PM12/2/09
to CSVChat
You just construct the CsvReader instance and either call ReadRecord
or ReadHeaders once. You can then access all the values in the row
through the corresponding properties depending on which method you
called. When you're done, just close the CsvReader instance. Reading
just the first row should be the same as reading the whole file, other
than you might have used CsvDataReader if you were bulk inserting the
file, but you'd want to use CsvReader to just read a single line.

Bruce Dunwiddie
Reply all
Reply to author
Forward
0 new messages