Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
csv = New CsvReader(New StreamReader("CSVFileLocation"), True)
Dim fieldCount As Integer = csv.FieldCount



The error message "An item with the same key has already been added." on the second line. If I changed "HasReaders" to "False", there's no such error. But, I'm not able to get the Headers.


which portion is treated as header




Statement,"5-jan-2013


04:29:55 PM",India and China Group ccn 11 005 357 522,Page -1 of 1,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,Col A,Col B,Col C,Col D,Col E,Col F,,,,,,,
05-Jan-13to 04-Jan-13,Xxxxxxx Name,Dxxxxx.Xccccc,IND,Xxxxxxx Number,00000-000000,Xxxxxxx uP,XN,FGHF Date,FGHF uP,Reference,UU,DSDD,Credits,Balance,,,,,,,,FDFe Brought YY,"585,688.71","FINFISHED

","75,299.90","27,985.63","538,374.44"
05-Jan-13to 04-Jan-13,Xxxxxxx Name,Dxxxxx.Xccccc,IND,Xxxxxxx Number,00000-000000,Xxxxxxx uP,XN,FGHF Date,FGHF uP,Reference,Narrative,Ers,Bl,05-jan-13.Bal,CV,"64,289.11",,,,,"FINFISHED

","75,299.90","27,985.63","538,374.44"
05-Jan-13to 04-Jan-13,Xxxxxxx Name,Dxxxxx.Xccccc,IND,Xxxxxxx 566,00000-000000,Xxxxxxx uP,XN,FGHF Date,FGHF uP,Reference,Narrative,Ers,Bl,05-jan-13.Bal,REFUND205932,B,LAL TT2 LLLLL FGFGFGFGF,"1,100.00",,,,,"FINFISHED

","75,299.90","27,985.63","538,374.44"
05-Jan-13to 04-Jan-13,Xxxxxxx Name,Dxxxxx.Xccccc,IND,Xxxxxxx Number,00000-000000,Xxxxxxx uP,XN,FGHF Date,FGHF uP,Reference,Narrative,Ers,Bl,05-jan-13.Bal,REFUND692248,B,LAL TT8 LLLLL DFDFDFDFD,"1,141.00",,,,,"FINFISHED

","75,299.90","27,985.63","538,374.44"
05-Jan-13to 04-Jan-13,Xxxxxxx Name,Dxxxxx.Xccccc,IND,Xxxxxxx Number,00000-000000,Xxxxxxx uP,XN,FGHF Date,FGHF uP,Reference,Narrative,Ers,Bl,05-jan-13.Bal,REFUND694266,B,LAL TT6 LLLLL FDDF5 KEY REFUND BENGT VON FDFN 694266,50,,,,,"FINFISHED

","75,299.90","27,985.63","538,374.44"
Posted
Updated 13-Jul-13 3:15am
v3
Comments
_Asif_ 13-Jul-13 6:44am    
am not able to understand your question.
siddharth629 15-Jul-13 2:12am    
sir ,i have a .csv file on local hard disk and was reading that file and printing that on excel sheet but i was getting exception what ever i mention above on line New CsvReader(New StreamReader("CSVFileLocation"), True) when i set true as false (header)then is run successfully
_Asif_ 15-Jul-13 2:38am    
Seems the first line of your csv file is empty. Make sure that there is no empty first line.
The first line of your CSV is the header line.
OriginalGriff 13-Jul-13 6:49am    
Perhaps if you showed us a small (the top five or so lines) of your CSVFileLocation file it would help...
Use the "Improve question" widget to edit your question and provide better information.
[no name] 13-Jul-13 8:02am    
The first line of your CSV file would be the header line.

1 solution

The first line of the file is the header row. You have to turn HasHeaders on in order to skip the header row so it doesn't become part of your data.

It's impossible to tell from the data you posted, because it lost all of it's formatting, but it may be that your CSV file has multiple header rows, in which case, it's not really a CSV.

If that's the case, you might have to pre-process the file to remove the header rows and leave just the data, passing the processed file to CsvReader.


Ask your question in the forum at the bottom of the article where you got the CsvReader class from. It seems to be a frequent problem with that library.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900