配置文件my.ini中我改了两个都为gb2312
数据库我也设置问gb2312了
连接字符串我也加了charset=gb2312。在每次执行前也加了 MySQLCommand myCmd = new MySQLCommand("SET NAMES gb2312", myConnection);
                    myCmd.ExecuteNonQuery();
在上面没弄之前查询出来中文是乱码,我按上面修改后查询出来正常了。但是我用MySQLParameter操作插入时就是乱码。
我的代码public int ExecuteCommand(string strSql, MySQLParameter[] paras)
        {
            try
            {
                using (MySQLConnection myConnection = new MySQLConnection(ContString))
                {
                    myConnection.Open();
                    MySQLCommand myCmd = new MySQLCommand("SET NAMES gb2312", myConnection);
                    myCmd.ExecuteNonQuery();
                    myCmd = new MySQLCommand(strSql, myConnection);
                    myCmd.Parameters.AddRange(paras);
                    int rowCount = myCmd.ExecuteNonQuery();
                    myConnection.Close();
                    return rowCount;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }很奇怪,如果参数中只有一个是中文就可以,如果出现两个和两个以上是中文参数就出错。