parsing - C# Importing CSV using OleDb -


i'm trying set code import .csv files .net.

i've tried both microsoft.jet.oledb.4.0 , microsoft.ace.oledb.12.0 providers, including modifying extended properties , modifying corresponding registry keys each. have yet come solution attempting do:

i import each field text, leave fields longer 255 characters un-truncated.

what i've found far can have 1 or other, not both.

  • if set importmixedtypes registry value majority type, leaves 255+ character text fields un-truncated, converts other fields unwanted types.
  • if set importmixedtypes registry value text, truncates 255+ character text fields, leaves other field types text.

how accomplish using oledb?


additional info:

i have "notes" column, can contain lengthy text. have "zip code" column, contains mixed zip-code formats (5-digit , 9-digit dash). typically, 5-digit zip-code format more popular, importer thinks column should integer type, leaving 9-digit zip-codes null values after import.

have considered using versatile filehelpers library (http://filehelpers.sourceforge.net/) instead?

or alternatively if requirements no more state (read csv file, string fields), use simple such as:

public static class simplecsvimport {     public static ienumerable<list<string>> import(string csvfilename)     {         using (var reader = file.opentext(csvfilename))         {             while (!reader.endofstream)             {                 var fields = reader.readline().split(new[] { ',' }, stringsplitoptions.none).select(f => f.trim()).tolist();                 if (fields.count > 0)                     yield return fields;             }         }     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -