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: