MySql Connector/Net Mysql like search for Chinese (c # And asp.net connect to mysql ),

Source: Internet
Author: User

MySql Connector/Net Mysql like search for Chinese (c # And asp.net connect to mysql ),
Connector/Net 6.9.8

Select. net/mono without installation.

Copy MySql. Data. dll of the corresponding version to the bin directory.

Http://dev.mysql.com/downloads/connector/net/

 

However, when using the like Statement of mysql to retrieve Chinese characters, data is always not retrieved. It turns out that this is a character encoding.

 

using MySql.Data.MySqlClient;
String query = @ "(SELECT * from TB where title LIKE '% %')"; MySqlConnection myConnection = new MySqlConnection ("server = 192.168.168.2; port = 3306; user id = uid; password = pwd; database = dba;Charset = utf8"); MySqlCommand myCommand = new MySqlCommand (query, myConnection); myConnection. open (); MySqlDataReader myDataReader = myCommand. executeReader (); while (myDataReader. read () = true) {string name = myDataReader ["name"]. toString (),} myDataReader. close (); myConnection. close ();

Note that it cannot be written as UTF-8

 

If the configuration file is used:

<add name="MySqlProductDB" connectionString="Server=192.168.100.104;Database=ProductDB;Uid=root;Pwd=JUSTZEE;charset=utf8" providerName="MySql.Data.MySQLCLIENT" />

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.