我正在尝试通过ADO.NET从DB获取输出值。有一个客户端代码:
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
SqlCommand command = new SqlCommand("pDoSomethingParamsRes", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@i", 1);
var outParam = new SqlParameter("@out", SqlDbType.VarChar);
outParam.Direction = ParameterDirection.Output;
command.Parameters.Add(outParam);
command.ExecuteNonQuery();
Console.WriteLine(command.Parameters["@out"].Value.ToString());
}
当我运行这段代码时,我得到了以下异常:
the Size property has an invalid size of 0
根据手册SqlParameter.Size Property,我可能会省略大小。为什么我会得到这个异常?
如何让它在不传递大小的情况下工作?
https://stackoverflow.com/questions/3759285
复制相似问题