Home >Database >Mysql Tutorial >Net、c# 连接Mysql数据库中文乱码

Net、c# 连接Mysql数据库中文乱码

WBOY
WBOYOriginal
2016-05-31 08:46:131116browse

网上有两种解决方案:

第一种是,每次执行语句的时候都和PHP的类似,先执行

一句“set names utf8”或者“set names gb2312”;

1 MySQLCommand setformat = new MySQLCommand("set names b2312",m_Connection);2 setformat.ExecuteNonQuery();3 setformat.Dispose();

第二种是,在webconfig里加一句“Charset=gbk”;

1 MySqlConnection myConnection = new MySqlConnection("Database=test2;Data Source=localhost;User Id=root;Password=ikmbikmb;Charset=gbk");

我是用第2中办法才得到了解决,第一种为什么不行?目前我还是个小白,暂时找不到原因,但肯定是程序和数据库对接,两个的默认编码不一致引起的。

最后还请多多指教!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn