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 a开发者_运维百科s 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?
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.
精彩评论