【发布时间】:2011-04-15 03:06:01
【问题描述】:
我正在尝试通过 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 我可能会省略尺寸。为什么会出现此异常?
如何在不传递大小的情况下使其工作?
【问题讨论】:
-
为什么要避免设置 Size 属性...
标签: c# sql-server ado.net