andrey.shedko
andrey.shedko

Reputation: 3238

"Too many arguments specified" when execute INSERT stored procedure

I'm stuck with a stored procedure on MSSQL 2008 R2. It looks correct but when I execute this stored procedure, I got the error "too many arguments specified". Here is SP code:

ALTER PROCEDURE [dbo].[InsertOrder] 
@KodT int, @kodG int, @Ad int, @Chd int, @PU datetime, @disc money, @Agent int, @PriceAd money, @PriceCh money 

AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @net money;
    DECLARE @netchd money;
    IF NOT EXISTS (SELECT КодЗ from Заказы Where Код = @KodT AND КодГ = @kodG)
    BEGIN
    SET @net = (SELECT Экскурсии.Net FROM Экскурсии INNER JOIN График ON График.Excursion = Экскурсии.Kod WHERE График.КодГ = @kodG);
    SET @netchd = (SELECT Экскурсии.NetChd FROM Экскурсии INNER JOIN График ON График.Excursion = Экскурсии.Kod WHERE График.КодГ = @kodG);
    END
    INSERT INTO Заказы (Код, КодГ, Pax, Child, PickUpTime, Discaunt, Продал, Price, PriceChd, Net, NetChd) 
    VALUES (@KodT, @KodG, @Ad, @Chd, @PU, @Disc, @Agent, @PriceAd, @PriceCh, @net, @netchd)
    END

Here is vb.net code:

With cmd
                    .Connection = ortsCon
                    .CommandText = "InsertOrder"
                    .CommandType = Data.CommandType.StoredProcedure
                    .Parameters.AddWithValue("@KodT", kodt)
                    .Parameters.AddWithValue("@KodG", kodg)
                    .Parameters.AddWithValue("@Ad", ad.Text)
                    .Parameters.AddWithValue("@Chd", ch.Text)
                    .Parameters.AddWithValue("@PU", pu.Text)
                    .Parameters.AddWithValue("@Disc", disc.Text)
                    .Parameters.AddWithValue("@Agent", userkod)
                    .Parameters.AddWithValue("@PriceAd", priceAd.Text)
                    .Parameters.AddWithValue("@PriceCh", priceCh.Text)
                End With
                ortsCon.Open()
                cmd.ExecuteNonQuery()
                cmd.Dispose()
                ortsCon.Close()

Upvotes: 1

Views: 896

Answers (1)

user806549
user806549

Reputation:

If you are doing this in a loop in the vb-code and don't clear the command object (or remove the parameters) between each iteration, you'll add a new set of parameters to the command each time.

This will cause the first iteration to function properly, but the second will report "Too many arguments specified".

Upvotes: 2

Related Questions