0

每次我运行我的更新函数时,我都会生成一个过程或函数有太多参数指定错误,我想我已经看这个太久了,因为我找不到根本原因。任何指导将不胜感激。

我的 VB.NET 代码如下:

    Public Function UpdateGenInfo_E1_01_02(ByVal pstrCon As String, _
                                     ByVal appNo As String, _
                                     ByVal revNo As String, _
                                     ByVal prName As String, _
                                     ByVal prAddr As String, _
                                     ByVal prAddr2 As String, _
                                     ByVal prCity As String, _
                                     ByVal prState As String, _
                                     ByVal prZip As String) As Integer
    Try


        'Create parameter
        Dim lsqlParams(8) As SqlParameter
        'fill parameter

        lsqlParams(0) = New SqlParameter("@AppNo", appNo)
        lsqlParams(1) = New SqlParameter("@RevNo", revNo)
        lsqlParams(2) = New SqlParameter("@PrName", prName)
        lsqlParams(3) = New SqlParameter("@PrAddr", prAddr)
        lsqlParams(4) = New SqlParameter("@PrAddr2", prAddr)
        lsqlParams(5) = New SqlParameter("@PrCity", prCity)
        lsqlParams(6) = New SqlParameter("@PrState", prState)
        lsqlParams(7) = New SqlParameter("@PrZip", prZip)
        'Return dataset
        Return SqlHelper.ExecuteNonQuery(pstrCon, CommandType.StoredProcedure, "up_UpdateGenInfo_E1_01_02", lsqlParams)
    Catch ex As Exception
        'Throw error

        Throw ex
    End Try
End Function

我的存储过程如下:

USE [EpUpdates]
GO
/****** Object:  StoredProcedure [dbo].[up_UpdateGenInfo_E1_01_02]    Script Date: 04/26/2013 12:00:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[up_UpdateGenInfo_E1_01_02] 
(

   @AppNo varchar(10),
   @RevNo varchar(4),
   @PrName varchar(10),
   @PrAddr varchar(50),
   @PrAddr2 varchar(50),
   @PrCity varchar(30),
   @PrState varchar(2),
   @PrZip varchar(10)
)
AS
   UPDATE EpUpdates.dbo.GenInfo_E1_01_02
   SET    PrName=@PrName,
          PrAddr=@PrAddr,
          PrAddr2= @PrAddr2,
          PrCity=@PrCity,
          PrState=@PrState,
          PrZip=@PrZip  
   WHERE (AppNo = @AppNo) 
     AND (RevNo = @RevNo)
4

1 回答 1

2

您在 VB 程序中有一个 C# 样式的数组长度说明符。

Dim lsqlParams(8) As SqlParameter     ' in C# this would create a length of 8 items.
                 ' in VB this creaes 9 items! (the upper bound of array)

您的错误是额外的空数组元素。更改为 (7)。

为了避免这种错误,我通常使用列表来累积项目(不喜欢设置数组编号)

Dim lsqlParams as new List(of SqlParameter)
lsqlParams.add(New SqlParameter(blah...))
' then pass to routine via ...
lsqlParams.ToArray
于 2013-04-26T17:01:47.903 回答