I'm Korean and I have a problem regards with importing csv file into DataTable.
I used this code to import csv file.
public static DataTable ParseCSV(string path)
{
string filePath = Path.GetDirectoryName(path);
string oledbConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";
string csvFileName = Path.GetFileName(path);
string sQuery = string.Format(" SELECT * FROM [{0}] ", csvFileName);
DataTable ds = null;
OleDbDataAdapter adt = null;
using (OleD开发者_如何学GobConnection con = new OleDbConnection(oledbConnectionString))
{
ds = new DataTable();
adt = new OleDbDataAdapter(sQuery, con);
adt.Fill(ds);
}
return ds;
}
It works very well when there is no Korean language in csv file.
However, if csv file contains korean word, it transfers korean word into some strange word.
I need your help.
Thank you~~~
Please try the following parser,
http://www.codeproject.com/KB/database/CsvReader.aspx
Save your csv file with UTF-8 encoding. This will more than likely solve your problem. You can use notepad++ to quickly convert your already saved file to UTF-8, run the import and see if that is working.
It happens to me. and i find that file that saved into utf-8 is the problem. you need to save the file as ANSI using notpad or what ever. then if you still have problem you need to add this row depand on the lenguage you need.
dataTable.Locale = CultureInfo.CurrentCulture;
or
dataTable.Locale = CultureInfo.GetCultureInfo(your culture);
here is the codes for the culture info.
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.71%29.aspx
精彩评论