0

WHERE status= 'โกดัง' " I try this it does not work ( it is utf8 (Thai language) Do I need to set up something in C# to make it know is utf8 or be cause of I can not use 'โกดัง'

I use c# and mysql the code is work until I fill WHERE status= 'โกดัง' before String cmdText = "SELECT * FROM trackingbymail "; it work

String str = @"server=localhost;database=asianimport;userid=tga;password=se57ui849;";


String cmdText = "SELECT * FROM trackingbymail WHERE  status=  'โกดัง' ";
                MySqlCommand cmd = new MySqlCommand(cmdText, con);
                MySqlDataReader reader = cmd.ExecuteReader();
Alex
  • 37,502
  • 51
  • 204
  • 332
  • 1
    "it does not work" Would you mind being a little more descriptive? – tnw Apr 16 '13 at 13:58
  • 2
    Check collation and character set of your db http://stackoverflow.com/questions/11170133/using-mysql-with-django-access-denied-for-user-localhost/11170252#11170252 – matcheek Apr 16 '13 at 14:01
  • the code is work until I fill WHERE status= 'โกดัง' before String cmdText = "SELECT * FROM trackingbymail "; it work – user2277775 Apr 16 '13 at 14:02

2 Answers2

2
  1. Ensure that the collation of your database of table is a UTF-8 collation (i.e. utf8_general_ci or one of its relations)

  2. Add Charset=utf8; to your connection string.

"Server=localhost;Database=test;Uid=test;Pwd=test;Charset=utf8;"

Source: MySQL C# Text Encoding Problems

Anyway if it can't solve, you can store the bytes instead the string. But probably it isn't the best way to solve that...

UTF8Encoding utf8 = new UTF8Encoding();
string unicodeString = "โกดัง";
byte[] encodedBytes = utf8.GetBytes(unicodeString);

then when you need you could back to string:

Encoding.UTF8.GetString(encodedBytes);
Community
  • 1
  • 1
Conrado Costa
  • 434
  • 2
  • 12
0

You should save your source code file as UTF-8.

Have you tried this?

emirc
  • 1,948
  • 1
  • 23
  • 38