我想调用以下存储过程为了选择子对象的颜色:
CREATE PROCEDURE `get_color`(
IN code VARCHAR(32) ,
OUT color enum('Blue','Green','White','Orange','Black'))
BEGIN
SELECT `Objects`.`subobject_id`
INTO @subobject
FROM `Objects`
WHERE `Objects`.`code` = code;
SELECT `SubObjects`.`color`
INTO color
FROM `SubObjects`
WHERE `SubObjects`.`id` = @subobject;
END
以下列方式从My sql查询窗口运行时,该过程正常工作:
set @object_code = 39164;
CALL get_color(@object_code, @color);
select @color;
我想在运行以下代码的c#应用程序中获得相同的结果:
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandText = "get_color";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.AddWithValue("@code", code);
command.Parameters["@code"].Direction = System.Data.ParameterDirection.Input ;
command.Parameters.AddWithValue("@color", MySqlDbType.VarChar);
command.Parameters["@color"].Direction = System.Data.ParameterDirection.Output;
MySqlDataReader rdr = command.ExecuteReader();
if ((rdr != null) && (rdr.HasRows) && (rdr.FieldCount == 1))
{
rdr.Read();
color = rdr.GetString(0);
rdr.Close();
}
else
{
rc = false;
}
不幸的是......当我调用'command.ExecuteReader()'时,会抛出以下异常:
mscorlib.dll中发生了未处理的“System.FormatException”类型异常 附加信息:输入字符串的格式不正确。
我在键盘上敲击我的头,试图理解格式中的错误:(
任何提示?