Wednesday, May 21, 2008

I resolved my own MySQL Unicode Problem

I just figured out what I did wrong: I forgot to specify character set in connection string. Once I added "charset=utf8" in the connection string, everything worked A OK.

Unicode and MySQL 5.0 ... almost there...

I just posted the following question in a forum:

---------------------
I was very pleased with Unicode support in MySQL 5.x . I could mix and match Japanese, Traditional Chinese and Simplified Chinese characters in a single nvarchar field. I could insert records using Navicat and then read them back from MySQL Query Browser. I can even read all these Unicode character using C# and Connector/N with no problem.

Trouble comes when I try to INSERT records into the table. All the Unicode characters turned into question marks. Since Unicode worked fine when I insert records into MySQL 5 with MySQL Query Browser, the issue should be on Connect/N.

I used direct SQL statement like this in C# (2.0):


command.CommandText = "INSERT INTO DiscCatalog (Disk, Name, Path, FullPath, Size, Date, Time, Category, Level, Files, Type) VALUES ('ペ', '尊重', 'ペ', '风云榜', '50 000 000', '5/12/2006', '13:29:30 PM', '', 3, 0, 'File')";
command.ExecuteNonQuery();

So do I need to explicitly do anything to tell MySqlCommand that the CommandText is a Unicode string?


---------------------