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?

2
  • possible duplicate of Read Csv file encoding error Commented Sep 16, 2011 at 11:34
  • Please try and keep your code readable! Commented Sep 16, 2011 at 12:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.