0

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

  :)

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by ArtistScope
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.