i using this system reference beginning e commerce c# when compile button place order..it error say "Procedure or function CreateCustomerOrder has too many arguments specified."

this my code checkout.aspx.cs

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web;
using CommerceLib;

public partial class Checkout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            PopulateControls();
    }

    // fill controls with data
    private void PopulateControls()
    {
        // get the items in the shopping cart
        DataTable dt = ShoppingCartAccess.GetItems();
        // populate the list with the shopping cart contents
        grid.DataSource = dt;
        grid.DataBind();
        grid.Visible = true;
        // display the total amount
        decimal amount = ShoppingCartAccess.GetTotalAmount();
        totalAmountLabel.Text = String.Format("{0:c}", amount);

        // check customer details
        bool addressOK = true;
        bool cardOK = true;
        if (Profile.Address1 + Profile.Address2 == ""
            || Profile.ShippingRegion == ""
            || Profile.ShippingRegion == "Please Select"
            || Profile.Country == "")
        {
            addressOK = false;
        }
        if (Profile.CreditCard == "")
        {
            cardOK = false;
        }

        // report / hide place order button
        if (!addressOK)
        {
            if (!cardOK)
            {
                InfoLabel.Text =
                  "You must provide a valid address and credit card "
                  + "before placing your order.";
            }
            else
            {
                InfoLabel.Text =
                 "You must provide a valid address before placing your "
                 + "order.";
            }
        }
        else if (!cardOK)
        {
            InfoLabel.Text = "You must provide a credit card before "
              + "placing your order.";
        }
        else
        {
            InfoLabel.Text =
              "Please confirm that the above details are "
              + "correct before proceeding.";
        }
        placeOrderButton.Visible = addressOK && cardOK;
        shippingSelection.Visible = addressOK && cardOK;

        // Populate shipping selection
        if (addressOK && cardOK)
        {
            int shippingRegionId = int.Parse(Profile.ShippingRegion);
            List<ShippingInfo> shippingInfoData =
               CommerceLibAccess.GetShippingInfo(shippingRegionId);
            foreach (ShippingInfo shippingInfo in shippingInfoData)
            {
                shippingSelection.Items.Add(
                  new ListItem(shippingInfo.ShippingType,
                    shippingInfo.ShippingID.ToString()));
            }
            shippingSelection.SelectedIndex = 0;
        }
    }

    protected void placeOrderButton_Click(object sender, EventArgs e)
    {
        // Store the total amount 
        decimal amount = ShoppingCartAccess.GetTotalAmount();
        // Get shipping ID or default to 0
        int shippingId = 0;
        int.TryParse(shippingSelection.SelectedValue, out shippingId);

        // Get tax ID or default to "No tax"
        string shippingRegion =
          (HttpContext.Current.Profile as ProfileCommon).ShippingRegion;
        int taxId;
        switch (shippingRegion)
        {
            case "2":
                taxId = 1;
                break;
            default:
                taxId = 2;
                break;
        }

        // Create the order and store the order ID
        string orderId =
          ShoppingCartAccess.[B]CreateCommerceLibOrder[/B](shippingId, taxId);
        // Redirect to the conformation page
        Response.Redirect("OrderPlaced.aspx");
    }


}

this is CreateCommerceLibOrder

 public static string CreateCommerceLibOrder(int shippingId, int taxId)
    {
        // get a configured DbCommand object
        DbCommand comm = GenericDataAccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "CreateCustomerOrder";
        // create parameters
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@CartID";
        param.Value = shoppingCartId;
        param.DbType = DbType.String;
        param.Size = 36;
        comm.Parameters.Add(param);
        // create a new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@CustomerID";
        param.Value = Membership.GetUser(
        HttpContext.Current.User.Identity.Name)
        .ProviderUserKey;
        param.DbType = DbType.Guid;
        param.Size = 16;
        comm.Parameters.Add(param);
        // create a new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@ShippingId";
        param.Value = shippingId;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);
        // create a new parameter
        param = comm.CreateParameter();
        param.ParameterName = "@TaxId";
        param.Value = taxId;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);
        // return the result table
        return GenericDataAccess.ExecuteScalar(comm);
    }
}

this is procedure CreateCustomerOrder

ALTER PROCEDURE CreateCustomerOrder 
(@CartID char(36),
 @CustomerID uniqueidentifier)
AS
/* Insert a new record into Orders */
DECLARE @OrderID int
INSERT INTO Orders (CustomerID) VALUES (@CustomerID)
/* Save the new Order ID */
SET @OrderID = @@IDENTITY
/* Add the order details to OrderDetail */
INSERT INTO OrderDetail 
     (OrderID, ProductID, ProductName, Quantity, UnitCost)
SELECT 
     @OrderID, Product.ProductID, Product.Name, 
     ShoppingCart.Quantity, Product.Price
FROM Product JOIN ShoppingCart
ON Product.ProductID = ShoppingCart.ProductID
WHERE ShoppingCart.CartID = @CartID
/* Clear the shopping cart */
DELETE FROM ShoppingCart
WHERE CartID = @CartID
/* Return the Order ID */
SELECT @OrderID

  :)

Dani AI

Generated

This error means the code is sending more parameters than the stored procedure declares. In your case (as shown by ) the data-access method builds four parameters (CartID, CustomerID, ShippingId, TaxId) but the SQL procedure only declares two parameters. Either stop passing the extra values from .NET, or change the stored procedure to accept and use them.

A safe stored-proc option (adds shipping/tax, prevents extra rowcount messages, and uses SCOPE_IDENTITY):

ALTER PROCEDURE CreateCustomerOrder
  @CartID CHAR(36),
  @CustomerID UNIQUEIDENTIFIER,
  @ShippingID INT = NULL,
  @TaxID INT = NULL
AS
SET NOCOUNT ON;

DECLARE @OrderID INT;

INSERT INTO Orders (CustomerID, ShippingID, TaxID)
VALUES (@CustomerID, @ShippingID, @TaxID);

SET @OrderID = CAST(SCOPE_IDENTITY() AS INT);

INSERT INTO OrderDetail (OrderID, ProductID, ProductName, Quantity, UnitCost)
SELECT @OrderID, p.ProductID, p.Name, sc.Quantity, p.Price
FROM Product p
JOIN ShoppingCart sc ON p.ProductID = sc.ProductID
WHERE sc.CartID = @CartID;

DELETE FROM ShoppingCart WHERE CartID = @CartID;

SELECT @OrderID;

If you prefer changing the .NET side, remove ShippingId/TaxId parameters (or only add them when the stored proc expects them). Also ensure the command is set to call a stored procedure and that the CustomerID value is passed as a Guid (not as a boxed object). Example checklist for the data-access code:

  • comm.CommandType = CommandType.StoredProcedure.
  • param for CustomerID uses a Guid value (cast ProviderUserKey to Guid).
  • parameter names match the proc exactly (including the @).
  • sizes/types match the DB types.

Quick extra tips: add SET NOCOUNT ON to the proc; prefer SCOPE_IDENTITY() over @@IDENTITY; confirm Orders has ShippingID/TaxID columns if you add those params; use SQL Profiler (or extended events) to see the actual parameter list the app sends. Also note 's remark about forum location — this is a .NET issue and belongs in the .NET section.

This forum is for Classic ASP, please post in the .NET section

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.