1.c# Winform connect MySQL to new MySQL, read data operation, use Mysql.MySql.Data component for data connection and operation
2.mysql Tutorial version of the lower 4.01 cannot be configured for the MySQL environment
Source: http://www.dezai.cn/blog/article.asp tutorial? id=418
Phenomenon:
1. New data normal operation, but insert MySQL database tutorial in the corresponding table data in the form of a question mark
The Chinese data displayed in the 2.Mysql table is normal, but the display is read by DataGridView.
Resolution process
1. In the version of MySQL 4.0.1 use set names ' gb2312 ' this statement is not feasible, but also to change the corresponding table of the field or character set seems to have no effect, more than 5.0 of the version has not been used, so can not provide a normal statement, you may try
MySQL Modify the character set of tables, fields, libraries
Http://www.dezai.cn/Channel/Code/Detail.aspx?CodeID=d3401000-2abd-4654-be6f-aa7c65c64ff1
2. The string attached to MySQL plus character Set=utf8 or charset=gb2312 should still be useful.
public static readonly String strsms = "Data source=188.28.1.36;user id=sale;password=sale;database=mas; Character Set=utf8; "
3. If it is b/s mode, you can try to save the page as UTF-8 format, or ANSI
4. The following two methods solve my big problem
Program code
//conversion when writing to the database
public string gb2312_iso8859 (string write)
{ br>//Declaration Character Set
System.Text.Encoding iso8859, gb2312;
//iso8859
iso8859 = System.Text.Encoding.GetEncoding ("iso8859-1");
//GB 2312
gb2312 = System.Text.Encoding.GetEncoding ("gb2312");
Byte[] GB;
GB = gb2312. GetBytes (write);
//Returns the converted character
return iso8859. GetString (GB);
}
//When read out
public string iso8859_gb2312 (string read)
{
//declaring character set
Syste M.text.encoding iso8859,gb2312;
//iso8859
iso8859 = System.Text.Encoding.GetEncoding ("iso8859-1");
//GB 2312
gb2312 = System.Text.Encoding.GetEncoding ("gb2312");
Byte[] ISO;
ISO = iso8859. GetBytes (read);
//Returns the converted character
return gb2312. GetString (ISO);
}