使用MySQLDriverCS 类操作MySql数据库时遇到中文乱码的问题,解决如下:
在执行SQL语句前,设置一下编码 set names gb2312 示例如下:
//
Some thing here
MySQLConnection myConn = new MySQLConnection(mySqlConnectionString);
myConn.Open();
MySQLCommand firstCmd = new MySQLCommand("set names gb2312", myConn);
firstCmd.ExecuteNonQuery();
string Sql = "select * from hooyes";
MySQLCommand cmd = new MySQLCommand();
cmd.Connection = myConn;
cmd.CommandText = Sql;
MySQLDataReader dr= cmd.ExecuteReaderEx();
//
.
![](https://www.cnblogs.com/Images/dot.gif)
MySQLConnection myConn = new MySQLConnection(mySqlConnectionString);
myConn.Open();
MySQLCommand firstCmd = new MySQLCommand("set names gb2312", myConn);
firstCmd.ExecuteNonQuery();
string Sql = "select * from hooyes";
MySQLCommand cmd = new MySQLCommand();
cmd.Connection = myConn;
cmd.CommandText = Sql;
MySQLDataReader dr= cmd.ExecuteReaderEx();
//
![](https://www.cnblogs.com/Images/dot.gif)
附:
MySQLDriverCS: An C# driver for MySQL. MySQLDriverCs 提供类似 SQLhelper 的方法访问 MySql 数据库,可以当它是一个 MySqlHelper 吧:)
MySQLDriverCS 下载:
本地: /Files/hooyes/MySQLDriverCS.rar