首先Mysql表,建表的时候,有没有选择UTF8,如果是默认的编码latin1,就会产生乱码

EntityFramewok 插入Mysql数据库 中文产生乱码解决

 

这里修改后,还是乱码,那就要检查发生乱码的列是不是UTF8格式

EntityFramewok 插入Mysql数据库 中文产生乱码解决

 

然后修改App.Config或者Web.Config文件, 加入Character Set=utf8 ,这里注意大小写。 然后再尝试插入新记录,乱码消失。

<configuration>
  <connectionStrings>
    <add name="EFEntity" connectionString="metadata=res://*/DBEntity.EFEntity.csdl|res://*/DBEntity.EFEntity.ssdl|res://*/DBEntity.EFEntity.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;Character Set=utf8;User Id=root;password=123321;database=world&quot;" providerName="System.Data.EntityClient"  />
  </connectionStrings>
</configuration>

相关文章:

  • 2021-11-20
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-04-05
猜你喜欢
  • 2021-12-03
  • 2021-09-30
  • 2021-10-15
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案