MySQL table and field encoding format error

Source: Internet
Author: User
Tags mysql connection string access database

MySQL table and field encoding format error

First, database, table, field encoding format are Latin1 (iso-8859-1). When the data is saved to the database, the Chinese display is garbled.

Workaround:

1. Add the encoding format to the Access database connection string:

<add key= "mysqlconnectionstring" value= "server=127.0.0.1; port=3306; UID=TTT; pwd=ttt;database=test_db;innercharacterset=gb2312;charset=gb2312 "/>

There is no problem with the information obtained in Chinese.

Note: Use the GB2312 encoding to add the Chinese information, read also use the same encoding format, that is, access to the encoding format to be consistent, otherwise obtained is garbled.

Second, if the obtained string is Latin1 encoded, in C # can do the following conversions:

<summary>
Latin1 (iso-8859-1) Turn gb2312 Chinese
</summary>
<param name= "str" ></param>
<returns></returns>
public static string Latin1toutf8 (String str) {
The gb2312 here depends on the character encoding set in the MySQL connection string.
Return encoding.getencoding ("gb2312"). GetString (encoding.getencoding ("iso-8859-1"). GetBytes (str));
}

MySQL table and field encoding format error

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.