“Size属性的大小为0。”

时间:2013-01-28 19:16:07

标签: .net sql-server vb.net

我正在使用此功能:

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

会导致此错误:

  

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

谁能看到我做错了什么?

2 个答案:

答案 0 :(得分:3)

尝试:

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

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

答案 1 :(得分:0)

我认为就是这条线:

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

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

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

就像我说的,这是猜测存储过程的哪一部分抛出异常