首页 > 编程技术 > csharp

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

发布时间:2020-6-25 11:39

有两种解决办法:

一种是在执行语句前面设置,如:

复制代码 代码如下:

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" /> 

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

标签:[!--infotagslink--]

您可能感兴趣的文章: