首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ADO.NET - Size属性的大小无效为0

ADO.NET - Size属性的大小无效为0
EN

Stack Overflow用户
提问于 2010-09-21 18:13:25
回答 10查看 63.4K关注 0票数 56

我正在尝试通过ADO.NET从DB获取输出值。有一个客户端代码:

代码语言:javascript
复制
    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());
    }

当我运行这段代码时,我得到了以下异常:

代码语言:javascript
复制
the Size property has an invalid size of 0

根据手册SqlParameter.Size Property,我可能会省略大小。为什么我会得到这个异常?

如何让它在不传递大小的情况下工作?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3759285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档