我坚持使用 MSSQL 2008 R2 上的存储过程。它看起来是正确的,但是当我执行这个存储过程时,我得到了错误“指定的参数太多”。这是SP代码:
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
这是vb.net代码:
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()