Click here to Skip to main content
14,773,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, what i'm doing right now is to import a csv file with chinese characters using OLEDB and write(OledbAdapter.Fill) it into datatable. When i read the info from the datatable, my expected info 刘三姐 become ÁõÈý½ã

What i have done:
1 - Set database and tables' character set to "utf8 -- UTF-8 Unicode" and collation is "utf8_general_ci".
2 - In web.config, add then info below in "globalization" tag below within the "system.web" tag:
requestencoding="utf-8" responseencoding="utf-8" fileencoding="utf-8" culture="" uiculture=""
3 - In html <head> tag, i include this line:
<META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
4 - My csvParses code:
string full = Path.GetFullPath(path);
string file = Path.GetFileName(full);
string dir = Path.GetDirectoryName(full);
string header = isHeader ? "Yes" : "No";

string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + dir + "\\\";Extended Properties=\"text;HDR=" + header + ";FMT=Delimited;CHARSET=utf8\"";
string query = "SELECT * FROM " + file;
DataTable dTable = new DataTable();
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
dAdapter.Fill(dTable);


When i get info from this dTable, the chinese characters become ÁõÈý½ã. May i know what are the things i might missing out? Your help is highly appreciated, thanks in advance.:)
Posted
Updated 4-Mar-20 7:17am
v4
Comments
   
I hope "Chinese" means Unicode, doesn't it? Also UTF-8? With or without BOM?
--SA
Member 8337007 21-Oct-11 3:48am
   
Thanks for reply:)
ya, it is Unicode and it is UTF-8 too. I'm not sure about the BOM. How can check whether my file is with/without BOM?
Actually i got this issue when i run my code in server. It runs as expected(show the correct chinese characters) in my localhost.
Do i missing out something?
Mehdi Gholam 21-Oct-11 2:59am
   
Have you checked your source file is correct ie has Chinese characters?
Member 8337007 21-Oct-11 3:50am
   
Thanks for reply:)
Ya, i checked my source file and it is correct (with chinese cheracters).
Actually i got this issue when i run my code in server. It runs as expected(show the correct chinese characters) in my localhost.
Do i missing out something?
Mehdi Gholam 21-Oct-11 4:14am
   
Check your servers locale settings also, it might be English.
Member 8337007 21-Oct-11 5:39am
   
For "Language for non-Unicode programs", the selected language is "English (United States)"; all options for "Code page conversion tables" had been selected; for "Supplemental language support", files for complex script and right-to-left languages as well as East Asian languages have been installed.
I think the system locale settings of server is in english (sorry, im not good in technical)

Try using this very good parser : A Fast CSV Reader[^]
   
The above solution did NOT work for me, but it was close.  What DID work:

Change the following lines from:
string file = Path.GetFileName(full);
string query = "SELECT * FROM " + file;
//The line with:
...FMT=Delimited;CHARSET=utf8\""

To:
string file = Path.GetFileName(stringFileName); //That is the name of your file
string query = "SELECT * FROM [" + file + "]"; //Need the brackets
//Change to:
...FMT=Delimited;CharacterSet=65001;\""
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900