It must be unified among the three, such as utf8,
1. MySQL: ensure that all columns are in utf8 format.
2. vs2010: When establishing a connection to the data server, select advance and set chracterset to utf8. In this way, when viewing and changing Mysql Data in vs2010, it won't see a lot of garbled characters because of the mismatch.
3. Entity Framework: our page uses EF to connect to MySQL, which also needs to be set here.
A. use a datasource to create a connection and save the connection string on the web. in config, set characterset to utf8, as in the previous connection. you can check in config, for example:
- <Add Name="Cheweidbcontext" Connectionstring="Server = localhost; user id = root; Password = 123456; persist Security info = true; character set = utf8; database = map" Providername="Mysql. Data. mysqlclient" />
B. When the EF model is created, the database connection will be selected, and the one mentioned in 1 will be selected. This will ensure that the web page is displayed, and the changed Chinese will be correctly updated to MySQL.
4. webpage: Set to utf8, as shown below:
- <Meta Content="Text/html; charset = UTF-8" HTTP-equiv="Content-Type" />
In my own situation, it is okay to insert Chinese Characters in sqlyog, but once it is inserted in the webpage, it will be displayed in the database ?? Garbled.
It can be seen that the encoding problem occurs when the entityframework is updated to the database. According to the above information,
In the Web. config file
<Add name = "testentities" connectionstring = "metadata = Res: // */models. article. CSDL | res: // */models. article. SSDL | res: // */models. article. MSL; provider = MySQL. data. mysqlclient; provider connection string = & quot; server = localhost; user id = root; Password = root; persist Security info = true; database = Test & quot; "providername =" system. data. entityclient "/>
Add character set = utf8.
The test is successful.