简体   繁体   中英

Procedure or function has too many arguments specified

I have code that uses a stored proc, but I get the error stated in title. I have gone through similar posts but I dont get n fix. I have made sure the amount of parameters is the same as in the stored proc.

    @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

And my VB code:

    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

Any Suggestions or fixes? I dont mind c# help.

You are adding your parameters to the command for each image, but you are not using a new SqlCommand for each image. So when your loop starts work on the first image there are 1 parameter in the SqlCommand . Then you add 6 parameters ( surl and co) and call the command. It has 7 parameters, all is well.

Then for the second image you add 6 parameters to the SqlCommand again on top of the 7 previous ones. Oops.

What you should do is instantiate the SqlCommand in the for loop in order to have the right parameters count at each call

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM