1. C # connect to MYSQL using Winform to add and read MySQL. mySql. data components for Data connection and operations 2. mysql versions earlier than 4.01 cannot be configured for the Mysql Environment
1. C # Use Winform to connect to MYSQL and read Data from MySQL. Use the Mysql. MySql. Data component to connect to and operate MYSQL.
2. mysql tutorial versions earlier than 4.01 cannot be configured for the Mysql Environment
Source: http://www.dezai.cn/blog/article.asptutorial? Id = 418
Symptom:
1. The new data operation is normal, but the data in the corresponding table in the MYSQL database tutorial is inserted as question marks.
2. The Chinese data in the Mysql table is displayed normally, but it is read and displayed through the datagridview? No.
Solution Process
1. in mysql 4.0.1, using the set names 'gb2312' statement does not work. Similarly, changing the field or character set of the corresponding table does not seem to work, versions later than 5.0 have not been used, so we cannot provide a normal statement. Please try again.
Mysql modifies the character set of tables, fields, and libraries.
Http://www.dezai.cn/Channel/Code/Detail.aspx? CodeID = d3401000-2abd-4654-be6f-aa7c65c64ff1
2. Adding Character Set = utf8 or charset = gb2312 to the string connecting to mysql still works.
Public static readonly string strSMS = "Data Source = 188.28.1.36; user id = sale; password = sale; database = mas; Character Set = utf8 ;"
3. for B/S mode, try to save the page as UTF-8 format, or ANSI format
4. The following two methods solve my big problem:
Program code
// 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 );
}