CSV column data is being truncated

2019-09-01 19:55发布

I am parsing a CSV file using Jet with the connection string

@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + directory + ";Extended Properties='text;HDR=YES;FMT=Delimited';"

with a Schema.ini containing:

[SelfCatering.csv]
Format=CSVDelimited
ColNameHeader=True
MaxScanRows=0

In my c# code I have predefined the column data types as string but for some reason extended string columns are being truncated at 255 characters. If I quick watch the column data itself is it only 255 letters long

Where else would it be getting truncated?

Thanks

标签: c# parsing csv
4条回答
Juvenile、少年°
2楼-- · 2019-09-01 20:15

You should try Datatype LongChar I had success with it.

查看更多
不美不萌又怎样
3楼-- · 2019-09-01 20:31

Dont use Jet OLEDB 4.0 driver, it will truncate your long text to 255 chars and it will read only 255 columns/fields. If you have more than 255 columns/fields you will not be able to read them all.

Other people on StackOverflow suggests to use: A Fast CSV Reader

查看更多
Evening l夕情丶
4楼-- · 2019-09-01 20:31

Have you tried specifying the field types in your Schema.ini file:

<SelfCatering.csv>
   You can add comments here
</SelfCatering.csv>

<schema.ini>
[SelfCatering.csv]
ColNameHeader=TRUE
MaxScanRows=0
Format=CSVDelimited
Col1=ColName1 Text Width 50
Col2=ColName2 Text Width 50
Col3=ColName3 Text Width 500
</schema.ini>
查看更多
Animai°情兽
5楼-- · 2019-09-01 20:34

Don't specify MaxScanRows=0. It is not working for some reason. Tried MaxScanRows=1000. It is working. or alternatively try edit registry

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Text] "MaxScanRows"=dword:00001000

查看更多
登录 后发表回答