MySqlCommand查询条件中包含中文没有结果的问题

在写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,重新运行程序,问题解决!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值