C # tips for developing MySQL Chinese garbled characters

Source: Internet
Author: User

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:

 
 
  1. 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.

 
 
  1. 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 ):

 
 
  1. CREATE TABLE TT (  
  2. id smallint(6) NOT NULL DEFAULT '1',  
  3. name varchar(64) NOT NULL,  
  4. descr varchar(64) DEFAULT NULL,  
  5. PRIMARY KEY (id)  

C # Insert the test data code into MySQL Chinese Garbled text processing:

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

C # program code: Query part of the code

 
 
  1. MySQLConnection con = new MySQLConnection("server=127.0.0.1;uid=root;pwd=;database=test;Charset=utf8");  
  2. con.Open();  
  3. DataSet ds = new DataSet();  
  4. MySQLDataAdapter adp = new MySQLDataAdapter("select * from TT",con);  
  5. adp.Fill(ds);  
  6. con.Close();  
  7. dataGridView1.DataSource = ds.Tables[0]; 

Insert some code:

Insert some code

 
 
  1. MySQLConnection con = new MySQLConnection ("server = 127.0.0.1; uid = root; pwd =; database = test; Charset = utf8 ");
  2. Con. Open ();
  3. String SQL = "insert into config TT ('4', 'hha ', 'haha ')";
  4. MySQLCommand cmd = new MySQLCommand (SQL, con );
  5. Cmd. ExecuteNonQuery ();
  6. 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.

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.