2013-03-27 110 views
0

我有一个返回输出的存储过程。存储过程中的输出参数定义如下:检索存储过程的输出参数的值

@Success int output 

我正在使用以下语句从输出参数中检索值。我收到错误消息

“指定的转换无效”

我使用Visual Studio 2012

int returnVal = (int)myCOmmand.Parameters["@Success"].Value; 

能否请您让我知道可能是什么问题?并提供解决方案。

感谢您的协助。 雅格亚

回答

1

我创建了一个参数,从执行,像这样(o_id是参数名)后获得的价值:

IDbDataParameter o_id = cmd.CreateParameter(); 
o_id.ParameterName = "?o_id"; 
o_id.DbType = DbType.Int32; 
o_id.Direction = ParameterDirection.Output; 
cmd.Parameters.Add(o_id); 

// Call the Stored Procedure 
cmd.CommandType = CommandType.StoredProcedure; 
cmd.CommandText "= MyStoredProcedure"; 

db.ExecuteNonQuery(cmd); 
int o_idValue = int.Parse(o_id.Value.ToString()); 

在这种情况下,db是一个数据库层,它执行我的IDbCommand

可能你可以用int.Parse()(或更好的,int.TryParse()