C# mysql 插入数据,中文乱码的解决方法

有两种解决办法:

一种是在执行语句前面设置,如:
复制代码 代码如下:
MySQLCommand mCommand = new MySQLCommand("set names gb2312", m_Connection);

另一种是直接加在连接字符串里,如:
复制代码 代码如下:
<add name="connection" connectionString="server=127.0.0.1;UId=root;PassWord=root;Persist Security Info=True;database=test;Charset=utf8;" providerName="MySql" /> 

我使用的是第二种,非常简单的解决了问题。

本文转自网络,如有侵权请联系客服删除。