C # coding problems and C # coding for MySQL plug-in data

Source: Internet
Author: User

public static    string  get_uft8 (String unicodestring)
{
UTF8Encoding UTF8 = new UTF8Encoding ();
byte[] encodedbytes = UTF8. GetBytes (unicodestring);
String decodedstring = UTF8. GetString (encodedbytes);
return decodedstring;
}

   This way, I'm taking Big5 conversion gb2312 as an example.
Encoding Big5 =encoding.getencoding ("Big5");
Encoding gb2312 = encoding.getencoding ("gb2312");


Byte[] big5b= Big5. GetBytes ("No Regrets!" ");
That's the point.
Byte[] gb2312b= Encoding.convert (big5,gb2312,big5b);

String strGb2312 = gb2312. GetString (gb2312b)

1: Add character encoding declaration in link character

<add key= "Mysqlconstr" value= "userid=root; Allow Zero datetime=true; Charset=utf8; Host=125.*.*.*;D Atabase=dbname; password=123456 "/>

String connectiontext = "Server=139.222.313.153;database=testsys; User=root; password=1123456; Charset=utf8; ";

Explain to MySQL that my character encoding is gb2312 or Utf-8, do not be mistaken.

As long as you are connected to MySQL, set the character set correctly, no matter what format the database is used to encode, you can get the correct result. Some people may think that the character set when writing data is required to be consistent with reading data, in fact it is completely unnecessary. The only thing that the program has to do is tell MySQL what character set is currently being used for MySQL operation. Because MySQL will automatically do the following conversion work:

The character set used to write the database--the character set of the data and the character set for reading the data.

C # coding problems and C # coding for MySQL plug-in data

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.