MySqlCommand查询条件中包含中文没有结果的问题
2016-01-22 16:24
666 查看
在写aps.net接口时,使用MySqlCommand执行查询语句select * from where name=’晓明’,数据库明明有’晓明’这条记录,但执行结果死活都是空,把数据库编码,程序编码都查了一遍没有找到问题,发现整个过程唯一不透明的地方就是MySqlCommand去执行查询的时候,因为不知道在这一层有没有对传入的中文字符做进一步处理,通过百度和google也没有找到有效的答案,于是去查MySqlCommand相关的属性和接口有没有和编码设置有关的,于是到MySQL官网去找,无意中发现一个页面有这样的介绍:
Important
If you are using multilanguage databases then you must specify the character set in the connection string. If you do not specify the character set, the connection defaults to the latin1 charset. You can specify the character set as part of the connection string, for example:
MySqlConnection myConnection = new MySqlConnection(“server=127.0.0.1;uid=root;” +
“pwd=12345;database=test;Charset=latin1;”);
页面url:http://dev.mysql.com/doc/connectors/en/connector-net-programming-connecting-errors.html
于是在数据库连接字符串中加入Charset=utf8,重新运行程序,问题解决!
Important
If you are using multilanguage databases then you must specify the character set in the connection string. If you do not specify the character set, the connection defaults to the latin1 charset. You can specify the character set as part of the connection string, for example:
MySqlConnection myConnection = new MySqlConnection(“server=127.0.0.1;uid=root;” +
“pwd=12345;database=test;Charset=latin1;”);
页面url:http://dev.mysql.com/doc/connectors/en/connector-net-programming-connecting-errors.html
于是在数据库连接字符串中加入Charset=utf8,重新运行程序,问题解决!
相关文章推荐
- 零积分下载,2014年辛星mysql教程秋季版第一本已经完工,期待您的支持
- 服务器,数据库连接注意mysql的user表
- MySql 里的IFNULL、NULLIF和ISNULL用法
- 【转】不用程序mysql也可以查询今天、昨天、7天、近30天、本月、上一月的数据
- mysqladmin命令修改Mysql密码
- MySQL 表分区梳理
- xampp修改mysql数据库密码
- mysql not in 或in 优化
- 【转】MYSQL 存储过程定时操作数据库
- mysql中myisamchk命令使用总结
- MySql—解压缩版本的安装与配制
- MySql的存储引擎
- 欢迎使用CSDN-markdown编辑器
- mysql安装一 --- 源码包安装
- EF+MySql
- MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码)
- MySQL C API mysql_free_result() 详解
- MySQL详解,第一章
- MySQL各版本的区别
- MySQL常见错误