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

时间:2014-05-02 08:09:15

标签: c# sql-server vb.net

我有使用存储过程的代码,但我收到标题中声明的错误。我已经通过类似的帖子,但我没有得到修复。我确保参数的数量与存储过程中的相同。

    @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#help。

1 个答案:

答案 0 :(得分:1)

您要将参数添加到每个图像的命令中,但您没有为每个图像使用新的SqlCommand。因此,当您的循环开始处理第一个图像时,SqlCommand中有1个参数。然后添加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