Click here to Skip to main content
15,920,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am reading a unicode data from a data base say MS Sql and trying to write in .CSV files. I am not able to write it properly it is replacing with '???'.

do any one has any idea?

Same problem i was facing when i was storing a unicode data in MYSQL data base.but i fixed this issue by converting wsrting to utf8.
Posted
Comments
JackDingler 9-Dec-11 10:10am    
Are you writing the BOM?

UTF-8, UTF-16, UTF-32 & BOM

1 solution

As you know from storing, it is a conversion problem. Database file usually use UTF-8 while Windows uses UTF-16LE (wchar). CSV files are mainly not Unicode but plain text. You should check if the program that should be used to read the CSV file supports Unicode encoded CSV files and which kind of encoding. If not, you may convert to an ANSI codepage.

In general:
Read from DB: Convert UTF-8 to wchar for processing
Write to DB: Convert wchar to UTF-8
Write CSV: Convert wchar to the encoding supported by the receiving program

When writing UTF files, you should place the BOM marker at the begin of file.

Jochen Arndt
 
Share this answer
 

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