1

I am trying to read / import CSV into data set with Following code

if (!File.Exists(file))
{
    File.Create(file).Close();
}

OleDbConnection connection = new System.Data.OleDb.OleDbConnection(
    "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + Path.GetDirectoryName(file) + 
    "; Extended Properties = \"Text;Excel 12.0;HDR=" + _AllowHeader + ";FMT=Delimited\"");

connection.Open();

string Query = "Select " + Count + " from [" + Path.GetFileName(_filename) + "]";

OleDbDataAdapter Adaptar = new System.Data.OleDb.OleDbDataAdapter(Query, connection);
Adaptar.Fill(DataSet);

It is fine With ANSI Encoded csv file as I can Import, but when I try to import UTF-8 or Unicode (Encoded) CSV File I got Byte Order Mark (BOM) in column Name.

My question is how can I prevent this and import any encoded CSV File?

Justin
  • 84,773
  • 49
  • 224
  • 367
Jones
  • 169
  • 3
  • 12

1 Answers1

1

You are probably better of using something other than Jet / Ace drivers to read or parse CSV data. At work we use this free library: http://www.filehelpers.com/

Looking at the documentation it appears to support different encoding types.

Kane
  • 16,471
  • 11
  • 61
  • 86