C#Mysql UTF8编码

T4m*_*mer 18 c# mysql utf-8 character-encoding

我有一个带有utf8_general_ci编码的mysql数据库,

我使用utf-8页面和文件编码连接到相同的数据库,没有问题但是当连接mysql与C#我有这样的字母غزة

我编辑连接字符串是这样的

server=localhost;password=root;User Id=root;Persist Security Info=True;database=mydatabase;Character Set=utf8
Run Code Online (Sandbox Code Playgroud)

但同样的问题.

x06*_*16e 32

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CharSet=utf8;
Run Code Online (Sandbox Code Playgroud)

注意!使用小写值utf8而不是大写UTF8,因为这将失败.

访问http://www.connectionstrings.com/mysql


Ant*_*ony 5

你能尝试一下:

Server=localhost;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;charset=utf8;"
Run Code Online (Sandbox Code Playgroud)

编辑:我有了一个新主意:

//To encode a string to UTF8 encoding
string source = "hello world";
byte [] UTF8encodes = UTF8Encoding.UTF8.GetBytes(source);

//get the string from UTF8 encoding
string plainText = UTF8Encoding.UTF8.GetString(UTF8encodes);
Run Code Online (Sandbox Code Playgroud)

祝好运

有关此技术的更多信息http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/BF68DDD8-3D95-4478-B84A-6570A2E20AE5