. Net Chinese Character garbled characters in MySQL operations

Source: Internet
Author: User

// Convert data when writing data to the database
Public String gb2312_iso8859 (string write)
{
// Declare the character set
System. Text. Encoding iso8859, gb2312;
// Iso8859
Iso8859 = system. Text. encoding. getencoding ("iso8859-1 ");
// 2312 GB
Gb2312 = system. Text. encoding. getencoding ("gb2312 ");
Byte [] GB;
GB = gb2312.getbytes (write );
// Return the converted characters
Return iso8859.getstring (GB );
}

// Convert data when reading data
Public String iso8859_gb2312 (string read)
{
// Declare the character set
System. Text. Encoding iso8859, gb2312;
// Iso8859
Iso8859 = system. Text. encoding. getencoding ("iso8859-1 ");
// 2312 GB
Gb2312 = system. Text. encoding. getencoding ("gb2312 ");
Byte [] ISO;
ISO = iso8859.getbytes (read );
// Return the converted characters
Return gb2312.getstring (ISO );
}

// Batch Data Conversion
// Read the content of dataset to the XML file and then output it.
Public dataset iso8859_gb2312 (Dataset DS)
{
String XML;
Xml = Ds. getxml ();
DS. Clear ();
// Declare the character set
System. Text. Encoding iso8859, gb2312;
// Iso8859
Iso8859 = system. Text. encoding. getencoding ("iso8859-1 ");
// 2312 GB
Gb2312 = system. Text. encoding. getencoding ("gb2312 ");
Byte [] Bt;
Bt = iso8859.getbytes (XML );
Xml = gb2312.getstring (BT );
DS. readxml (new system. Io. stringreader (XML ));
Return Ds;
}

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.