2013-04-26 76 views
0

每次我運行我的更新函數時,我生成一個過程或函數有太多的參數指定的錯誤,我想我一直在尋找這個太久因爲我找不到根本原因。任何指導將不勝感激。過程或函數具有太多的參數在ASP.NET中使用VB.NEt指定

我的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 [email protected], 
      [email protected], 
      PrAddr2= @PrAddr2, 
      [email protected], 
      [email protected], 
      [email protected] 
    WHERE (AppNo = @AppNo) 
    AND (RevNo = @RevNo) 
+0

我認爲'(「@ PrAddr2」,PRADDR)'只是一個錯字,並這不可能是你真正的問題。 – 2013-04-28 04:50:29

回答

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 
+1

我將數組長度從8更改爲7,但我仍然生成相同的錯誤。 – 2013-04-26 17:08:20

+0

如果可能,請將確切的錯誤文本添加到問題中 – DarrenMB 2013-04-26 17:11:45

+0

我收到的確切錯誤是up_UpdateGenInfo_E1_01_02指定的參數太多。我也嘗試使用你的其他方法使用列表,但沒有太多的運氣。 – 2013-04-26 17:22:47

相關問題