日期:2014-05-16  浏览次数:20664 次

C# 中调用mySql带参数的存储过程 出现的问题
存储过程代码:
SQL code

ALTER DEFINER=`root`@`localhost` PROCEDURE `GetTestProgramByNameAndVersion`(in _displayName varchar(255),in _version char(10))
BEGIN
   select Id,DisplayName,Version from testpragram where DisplayName=_displayName and Version=_version;
END



ExcuteReader方法代码:
C# code

        public MySqlDataReader ExcuteReader(string sql, CommandType type, params MySqlParameter[] parameters)
        {
            MySqlConnection conn = null;
            try
            {
                conn = GetOpenedConnection();
                MySqlCommand command = new MySqlCommand(sql, conn);
                command.CommandType = type;
                if (parameters != null)
                {
                    command.Parameters.AddRange(parameters);
                }
                return command.ExecuteReader();
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message);
            }
        }



C#调用代码:
C# code

       MySqlParameter param1=new MySqlParameter("?_displayName",MySqlDbType.String,255);
       param1.Value="MySql存储过程测试";
       MySqlParameter param2=new MySqlParameter("?_version",MySqlDbType.String,10);
       param2.Value="0.02";
       MySqlParameter[] parameters = { param1, param2 };
       MySqlDataReader reader = ExcuteReader("GetTestProgramByNameAndVersion", CommandType.StoredProcedure, parameters);



异常信息:
Incorrect string value: '\xB4\xE6\xB4\xA2\xB9\xFD...' for column '_displayName' at row 17

各位大侠 帮忙啊!很急的

------解决方案--------------------
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码
------解决方案--------------------
字符集有问题
show variables like '%char%';
设置字符集
set names gbk;