C # develop MySQL Chinese garbled Processing

Source: Internet
Author: User

Development Environment:
Vs 2008 + easyphp5.3.0 + win7
Problem description: The Chinese characters inserted in MySQL are displayed as question marks, and reading is also displayed as question marks.
C # The component used to access the database is MySQL. Data. dll (5.0.8.1)

The code for creating a test table is as follows (Make sure to change the database to utf8_general_ci during database creation.):

Create Table TT (
Id smallint (6) Not null default '1 ',
Name varchar (64) not null,
Descr varchar (64) default null,
Primary Key (ID)
)

Insert test data code:

Insert into config TT ('4', 'hha ', 'haha ')

C # program code:

Query part of the code

Mysqlconnection con = new mysqlconnection ("Server = 127.0.0.1; uid = root; Pwd =; database = test; charset = utf8 ");
Con. open ();
Dataset DS = new dataset ();
Mysqldataadapter ADP = new mysqldataadapter ("select * from TT", con );
ADP. Fill (DS );
Con. Close ();
Datagridview1.datasource = Ds. Tables [0];

Insert some code:

Insert some code

Mysqlconnection con = new mysqlconnection ("Server = 127.0.0.1; uid = root; Pwd =; database = test; charset = utf8 ");
Con. open ();
String SQL = "insert into config TT ('4', 'hha ', 'haha ')";
Mysqlcommand cmd = new mysqlcommand (SQL, con );
Cmd. executenonquery ();
Con. Close ();

The final effect is as follows:

Development Environment:
Vs 2008 + easyphp5.3.0 + win7
Problem description: The Chinese characters inserted in MySQL are displayed as question marks, and reading is also displayed as question marks.
C # The component used to access the database is MySQL. Data. dll (5.0.8.1)

The code for creating a test table is as follows (Make sure to change the database to utf8_general_ci during database creation.):

Create Table TT (
Id smallint (6) Not null default '1 ',
Name varchar (64) not null,
Descr varchar (64) default null,
Primary Key (ID)
)

Insert test data code:

Insert into config TT ('4', 'hha ', 'haha ')

C # program code:

Query part of the code

Mysqlconnection con = new mysqlconnection ("Server = 127.0.0.1; uid = root; Pwd =; database = test; charset = utf8 ");
Con. open ();
Dataset DS = new dataset ();
Mysqldataadapter ADP = new mysqldataadapter ("select * from TT", con );
ADP. Fill (DS );
Con. Close ();
Datagridview1.datasource = Ds. Tables [0];

Insert some code:

Insert some code

Mysqlconnection con = new mysqlconnection ("Server = 127.0.0.1; uid = root; Pwd =; database = test; charset = utf8 ");
Con. open ();
String SQL = "insert into config TT ('4', 'hha ', 'haha ')";
Mysqlcommand cmd = new mysqlcommand (SQL, con );
Cmd. executenonquery ();
Con. Close ();

The final effect is as follows:

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.