过程或函数指定的参数太多

本文关键字:参数 太多 函数 过程 | 更新日期: 2023-09-27 18:01:11

我有使用存储过程的代码,但我得到了标题中所述的错误。我也发过类似的帖子,但我没有得到解决。我已经确保参数的数量与存储过程中的相同。

    @stype as varchar,
    @surl as varchar(500),
    @status as bigint,
    @pk_photo_id as bigint,
    @bactive as bigint,
    @property_id as varchar(30),
    @client_id as bigint   
.... rest of code
 if (@stype = 'L')
        BEGIN
            update ET_PROPERTY_PHOTO set sLarge_Url=@surl, idownloaded=@status where pk_Property_Photo_ID=@pk_photo_id
            if (@bactive=1)
            BEGIN
                update ET_PROPERTY set slarge_url=@surl where (Property_ID=@property_id) and (@client_id = fkl_XML_Client_ID)
            END
....rest of code

我的VB代码:

    Dim cmdSet As New SqlCommand("ETSP_UPDATE_PHOTO_URLS")
    cmdSet.CommandType = CommandType.StoredProcedure
    cmdSet.Parameters.AddWithValue("@stype", "L")
    Try
        Dim utility As New TransferUtility(AWSAccessKey, AWSSecretKey, RegionEndpoint.EUWest1)
        Dim S3_KEY As String = sKey
        Dim txtFolderPath As String = "C:''images''"
        Dim bucket As String = ConfigurationSettings.AppSettings("bucket")
        Dim files As String() = Directory.GetFiles(txtFolderPath)
        For Each images As String In files
            Dim id As String = ""
            For Each str As String In IDS
                If Path.GetFileNameWithoutExtension(sKey).Contains(str) Then
                    id = str
                End If
            Next
            utility.Upload(txtFolderPath & sKey, bucket)
            Dim cannedACL As S3CannedACL = S3CannedACL.PublicRead

            Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sKey)
            Dim token As String = fileNameOnly.Remove(fileNameOnly.LastIndexOf("_"c))
            Dim number As New String(token.SkipWhile(AddressOf [Char].IsLetter).ToArray())
            cmdSet.Parameters.AddWithValue("@surl", Convert.ToString("URL" & sKey))
            cmdSet.Parameters.AddWithValue("@status", 2)
            cmdSet.Parameters.AddWithValue("@pk_photo_id", number)
            cmdSet.Parameters.AddWithValue("@bactive", 1)
            cmdSet.Parameters.AddWithValue("@property_id", id)
            cmdSet.Parameters.AddWithValue("@client_id", clientIDs)
    ....code

有什么建议或解决方案吗?我不介意c#帮忙。

过程或函数指定的参数太多

您正在为每个图像向命令添加参数,但没有为每个图像使用新的SqlCommand。因此,当循环开始处理第一个图像时,SqlCommand中有一个参数。然后添加6个参数(surl和co(并调用该命令。它有7个参数,一切都很好。

然后,对于第二个图像,在之前的7个参数的基础上,再次向SqlCommand添加6个参数。哎呀。

您应该做的是在for循环中实例化SqlCommand,以便在每次调用时都有正确的参数计数

Try
    Dim utility As New TransferUtility(AWSAccessKey, AWSSecretKey, RegionEndpoint.EUWest1)
    Dim S3_KEY As String = sKey
    Dim txtFolderPath As String = "C:''images''"
    Dim bucket As String = ConfigurationSettings.AppSettings("bucket")
    Dim files As String() = Directory.GetFiles(txtFolderPath)
    For Each images As String In files
        Dim id As String = ""
        For Each str As String In IDS
            If Path.GetFileNameWithoutExtension(sKey).Contains(str) Then
                id = str
            End If
        Next
        utility.Upload(txtFolderPath & sKey, bucket)
        Dim cannedACL As S3CannedACL = S3CannedACL.PublicRead

        Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sKey)
        Dim token As String = fileNameOnly.Remove(fileNameOnly.LastIndexOf("_"c))
        Dim number As New String(token.SkipWhile(AddressOf [Char].IsLetter).ToArray())
        Dim cmdSet As New SqlCommand("ETSP_UPDATE_PHOTO_URLS")
        cmdSet.CommandType = CommandType.StoredProcedure
        cmdSet.Parameters.AddWithValue("@stype", "L")
        cmdSet.Parameters.AddWithValue("@surl", Convert.ToString("URL" & sKey))
        cmdSet.Parameters.AddWithValue("@status", 2)
        cmdSet.Parameters.AddWithValue("@pk_photo_id", number)
        cmdSet.Parameters.AddWithValue("@bactive", 1)
        cmdSet.Parameters.AddWithValue("@property_id", id)
        cmdSet.Parameters.AddWithValue("@client_id", clientIDs)
....code