vb.net “Size 属性的大小无效,为 0。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14569433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:04:19  来源:igfitidea点击:

"Size property has an invalid size of 0."

.netsql-servervb.net

提问by user2008654

I am using this function:

我正在使用这个功能:

Private Sub Trigger_sales(HIden As Guid)
        Dim connection As New SqlConnection(connectionString)
        connection.Open()
        Dim Command As New SqlCommand()
        Command.Connection = connection
        Command.CommandType = CommandType.StoredProcedure
        Command.CommandText = "[WebSite].[ValidateWebTran]"
        Command.Parameters.Add("@UidWenTranGUID", SqlDbType.UniqueIdentifier)
        Command.Parameters("@UidWenTranGUID").Value = HIden
        Command.Parameters.Add("@sResultDesc", SqlDbType.VarChar)
        Command.Parameters("@sResultDesc").Direction = ParameterDirection.Output
        Command.ExecuteScalar()
        If (String.IsNullOrEmpty(error_process.text = Command.Parameters("@sResultDesc").Value.ToString)) Then
            complete_sales(HIden)
        End If
    End Sub

which results in this error:

这导致此错误:

String[1]: the Size property has an invalid size of 0.

String[1]:Size 属性的大小无效,为 0。

Can anyone see what I'm doing wrong?

谁能看到我做错了什么?

回答by Aaron Bertrand

Try:

尝试:

Command.Parameters.Add("@sResultDesc", SqlDbType.VarChar, 255)

(Replace 255with whatever parameter type @sResultDescis. If it is MAXuse -1.)

(替换255为任何参数类型@sResultDesc。如果MAX使用-1。)

回答by Scott Selby

I think it's this line:

我认为是这一行:

Command.Parameters.Add("@sResultDesc", SqlDbType.VarChar)

you're not actually setting the value of the Param there , it should look like

你实际上并没有在那里设置 Param 的值,它应该看起来像

Command.Parameters.Add("@sResultDesc", SqlDbType.VarChar).Value = 'myValue

Like I said , this is a guess from what part of your stored procedure is throwing exception

就像我说的,这是从您的存储过程的哪一部分引发异常的猜测