Home  >  Article  >  Database  >  解决Mysql插入中文乱码问题:Incorrect string value: ‘xA8Dx

解决Mysql插入中文乱码问题:Incorrect string value: ‘xA8Dx

WBOY
WBOYOriginal
2016-06-07 15:52:421135browse

之前几次碰到插入数据库的时候提示 Incorrect string value: ‘\xA8D\xA8D\xBA\xE1…’ for column ‘content’ at row 1 一般都是插入中文的时候就提示了、 解决办法是, 在插入数据库之前 先执行一次mysql_qeury(“set names gbk”) 确定好字符编码, 还有

之前几次碰到插入数据库的时候提示 Incorrect string value: ‘\xA8D\xA8D\xBA\xE1…’ for column ‘content’ at row 1

一般都是插入中文的时候就提示了、

解决办法是, 在插入数据库之前 先执行一次mysql_qeury(“set names gbk”) 确定好字符编码,

还有可能要选择数据库校对码。


-----------------------------------------------------

C#代码:

            MySQLConnection conn = new MySQLConnection("Data Source=testdb;Password=123456;User ID=root;Location=localhost;Port=3306;charset=gbk");
            MySQLCommand cmdSet = new MySQLCommand("set names gbk", conn);
            MySQLCommand cmd = new MySQLCommand("INSERT INTO textTest(D_txt) VALUES ('" + textBox1.Text + "')", conn);
            conn.Open();
            cmdSet.ExecuteNonQuery();
            int result = (int)cmd.ExecuteNonQuery();
            conn.Close();
            MessageBox.Show(result.ToString());


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn