Click here to Skip to main content
15,921,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting error like
Procedure or function has too many arguments specified

but i have specified the arguments correctly
my procedure
CREATE PROCEDURE [dbo].[rsa_products_sp_Insertordersummary]
      @UserId int,
      @productid int,
      @productname NVARCHAR(50),
      @ProductImage image,
      @price float,
      @qty int,
      @totalcost decimal(18, 2)
AS
BEGIN
      SET NOCOUNT ON;
      IF NOT EXISTS(SELECT * FROM rsa_Orderconfirmation WHERE productid=@productid)
            INSERT INTO [rsa_Orderconfirmation]
                     ([UserId]
                     ,[productid]
                     ,[productname]
                     ,[ProductImage]
                     ,[price]
                     ,[qty]
                     ,[totalcost]
                     ,[cdate])
            VALUES
                     (@UserId
                     ,@productid
                     ,@productname
                     ,@ProductImage
                     ,@price
                     ,@qty
                     ,@totalcost
                     ,GETDATE())             
END
GO

My cs code as follows

C#
foreach (GridViewRow gvr in Gridcart.Rows)
            {
                string ProductID = Gridcart.DataKeys[gvr.RowIndex].Values["productid"].ToString();
                Application["id"] = ProductID;
                string proid = Application["id"].ToString();
                da = new SqlDataAdapter("select tpd.productid,tpd.productname,tpd.ProductImage,tpd.price,tpd.qty,tpd.totalcost,tpd.cdate from rsa_addtocart tpd where tpd.productid=" + proid + "", con);
                ds = new DataSet();
                da.Fill(ds, "tbl_tpd");
               if (ds.Tables.Count > 0 && ds.Tables["tbl_tpd"].Rows.Count > 0)
               {
                   using (var command = new SqlCommand("rsa_products_sp_Insertordersummary", con))
                {
                    foreach (DataRow theRow in ds.Tables["tbl_tpd"].Rows)
                    {
                        command.Parameters.Clear();
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@UserId", Session["users"]);
                        command.Parameters.AddWithValue("@productid", ds.Tables[0].Rows[0]["productid"]);
                        command.Parameters.AddWithValue("@productname", ds.Tables[0].Rows[0]["productname"]);
                        command.Parameters.AddWithValue("@ProductImage", ds.Tables[0].Rows[0]["ProductImage"]);
                        command.Parameters.AddWithValue("@price", ds.Tables[0].Rows[0]["price"]);
                        command.Parameters.AddWithValue("@qty", ds.Tables[0].Rows[0]["qty"]);
                        command.Parameters.AddWithValue("@totalcost", ds.Tables[0].Rows[0]["totalcost"]);
                        command.Parameters.AddWithValue("@cdate", DateTime.Now);
                         if (con.State != ConnectionState.Open)
                        {
                            con.Open();
                            try
                            {
                                command.ExecuteNonQuery();
                            }
                            finally
                            {
                                con.Close();
                            }
                        }
                        else
                        {
                            command.ExecuteNonQuery();
                            con.Close();
}
}
}
}
}

What I'm doing wrong in the stored procedure please help me to solve this.
Posted

Count the number of params in the SP and count the number in your code. You're adding a param called @cdate but the SP doesn't have that param, exactly like the error message is saying.
 
Share this answer
 
Comments
Andy Lanng 3-Jul-15 5:56am    
Gah - you beat me to it :P
+5. Correct.
There is no parameter @cdate.

The SP has 7 params - You are defining 8
C#
command.Parameters.AddWithValue("@cdate", DateTime.Now);


cdate is currently GetDate() in the SP so you may not need it at all, anymore
 
Share this answer
 
@cdate parameter you have specified is not declared or exists in your stored procedure.
so remove it from code or add parameter @cdate in your stored procedure...
 
Share this answer
 
Extra Parameter added in the form of @CDate
 
Share this answer
 
Add @cDate Parameter to sp or Remove the @cDate in your Code behind.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900