SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[SP_UpdateProducts] ( @PID int, @Quantity int ) AS BEGIN SET NOCOUNT ON; UPDATE tblProducts SET PQuantity = @Quantity WHERE PID = @PID END
create table tblProducts ( PID int identity(1,1) primary key, PName nvarchar(MAX), PPrice money, PSelPrice money, PBrandID int, PCategoryID int, PSubCatID int, PGender int, PQuantity int, PDescription nvarchar(MAX), PProductDetails nvarchar(MAX), PMaterialCare nvarchar(MAX), FreeDelivery int, [30DayRet] int, COD int, Constraint [FK_tblProducts_ToTable] FOREIGN KEY ([PBrandID]) REFERENCES [tblBrands] ([BrandID]), Constraint [FK_tblProducts_ToTable1] FOREIGN KEY ([PCategoryID]) REFERENCES [tblCategory] ([CatID]), Constraint [FK_tblProducts_ToTable2] FOREIGN KEY ([PSubCatID]) REFERENCES [tblSubCategory] ([SubCatID]), Constraint [FK_tblProducts_ToTable3] FOREIGN KEY ([PGender]) REFERENCES [tblGender] ([GenderID]) )
<pre> protected void btnBuyNow_Click(object sender, EventArgs e) { Int32 UserID = Convert.ToInt32(Session["USERID"].ToString()); //This will add +1 to current quantity using PID int PID = Convert.ToInt32(Request.QueryString["PID"]); using (SqlConnection con = new SqlConnection(CS)) using (SqlCommand cmd = new SqlCommand("SP_UpdateProducts", con) { CommandType = CommandType.StoredProcedure }) { DataTable dt = new DataTable(); using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { sda.Fill(dt); } foreach (DataRow row in dt.Rows) { int myQty = row.Field<int>("Qty"); int PQuantity = row.Field<int>("PQuantity"); if (myQty < PQuantity) { int updateQty = row.Field<int>("Qty"); cmd.Parameters.AddWithValue("@Quantity", PQuantity - updateQty); cmd.Parameters.AddWithValue("@PID", PID); cmd.ExecuteNonQuery(); con.Open(); Response.Redirect("OrderConfirmation.aspx"); } } } }
tblProducts does not updated and get error Procedure or function 'SP_UpdateProducts' expects parameter '@PID', which was not supplied.
null
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)