The following articles mainly introduce the correct solution for C # To develop MySQL Chinese garbled characters, including the development environment and related problem descriptions, and the description of the Code that needs to be inserted into the test data during MySQL Chinese garbled processing in C # development. The following describes the main content of the article.
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. dll5.0.8.1)
The code for creating a table for testing is as follows: note that when creating a database, change it to utf8_general_ci ):
- CREATE TABLE TT (
- id smallint(6) NOT NULL DEFAULT '1',
- name varchar(64) NOT NULL,
- descr varchar(64) DEFAULT NULL,
- PRIMARY KEY (id)
- )
C # Insert the test data code into MySQL Chinese Garbled text processing:
- 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:
The above content describes how to process MySQL Chinese garbled characters in C # development, hoping to help you in this aspect.