Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 4th, 2004, 08:34 PM
Authorized User
 
Join Date: Jun 2004
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default Input String was not in a correct format

Friends
I think this is due to some problem in my stored procedure.
Please, please take a look and tell me what is it that I am doing wrong. I have a product page from which users can select color, size, and width from three drop down lists. When they click "Add To Cart", the following routine fires:

private void processCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddToCart"))

            {
                DropDownList ddlColor = (DropDownList)e.Item.FindControl("ddlColor");
                DropDownList ddlSize = (DropDownList)e.Item.FindControl("ddlSize");
                DropDownList ddlWidth = (DropDownList)e.Item.FindControl("ddlWidth");
                Server.Transfer("PPAddToCart.aspx?ProductID=" + e.CommandArgument.ToString()+ "&shoecolor=" + ddlColor.SelectedValue.ToString() + "&shoesize=" + ddlSize.SelectedValue.ToString() + "&shoewidth=" + ddlWidth.SelectedValue.ToString());
            }

        }

As you can see, this is transferred to PPAddToCart.aspx which on Page Load does the following routine:

public PPAddToCart()
        {
            Page.Init += new System.EventHandler(Page_Init);
        }


        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here

            if (Request.Params["ProductID"] != null)
            {
                perrysplace.ppShoppingCartDB cart = new ppShoppingCartDB();

                String CartId = cart.GetShoppingCartId();
                String shoecolor = Request.QueryString["shoecolor"];
                String shoesize = Request.QueryString["shoesize"];
                String shoewidth = Request.QueryString["shoewidth"];





                cart.AddItem(CartId, Int32.Parse(Request.Params["ProductID"]), 1, shoecolor, shoesize, shoewidth);
            }
            Response.Redirect("PPShoppingCart.aspx");
        }

        private void Page_Init(object sender, EventArgs e)
        {
            InitializeComponent();
        }


Here is the SPROC that performs the AddItem method, following which is the method itself.


CREATE Procedure PPShoppingCartAddItem
(
    @CartID nvarchar(50),
    @ProductID int,
    @Quantity int,
    @Color nvarchar(50) = null,
    @ShoeSize nvarchar(50) = null,
    @Width nvarchar(50) = null
)
As

IF LEN(RTRIM(LTRIM(@Color))) = 0 SELECT @Color = null
IF LEN(RTRIM(LTRIM(@ShoeSize))) = 0 SELECT @ShoeSize = null
IF LEN(RTRIM(LTRIM(@Width))) = 0 SELECT @Width = null

DECLARE @CountItems int

SELECT
    @CountItems = Count(ProductID)
FROM
    PPShoppingCart
WHERE
    ProductID = @ProductID
  AND
    CartID = @CartID

IF @CountItems > 0 /* There are items - update the current quantity */

    UPDATE
        PPShoppingCart
    SET
        Quantity = (@Quantity + PPShoppingCart.Quantity)
    WHERE
        ProductID = @ProductID
      AND
        CartID = @CartID

ELSE /* New entry for this Cart. Add a new record */





    INSERT INTO PPShoppingCart
    (
        CartID,
        Quantity,
        ProductID,
    Color,
    ShoeSize,
    Width

    )
    VALUES
    (
        @CartID,
        @Quantity,
        @ProductID,
    @Color,
    @ShoeSize,
    @Width

    )
GO


Here is the AddItem method:

public void AddItem(string cartID, int productID, int quantity, string color, string size, string width)
        {
            //This method add items to shopping cart. Important method!!
            SqlConnection cnCart = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand cmdSelect = new SqlCommand("PPShoppingCartAddItem", cnCart);

            cmdSelect.CommandType = CommandType.StoredProcedure;

            SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
            parameterProductID.Value = productID;
            cmdSelect.Parameters.Add(parameterProductID);

            SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
            parameterCartID.Value = cartID;
            cmdSelect.Parameters.Add(parameterCartID);

            SqlParameter parameterQuantity = new SqlParameter("@Quantity", SqlDbType.Int, 4);
            parameterQuantity.Value = quantity;
            cmdSelect.Parameters.Add(parameterQuantity);

            SqlParameter parameterColor = new SqlParameter("@Color", SqlDbType.NVarChar, 50);
            parameterQuantity.Value = color;
            cmdSelect.Parameters.Add(parameterColor);

            SqlParameter parameterShoeSize = new SqlParameter("@ShoeSize", SqlDbType.NVarChar, 50);
            parameterQuantity.Value = size;
            cmdSelect.Parameters.Add(parameterShoeSize);

            SqlParameter parameterWidth = new SqlParameter("@Width", SqlDbType.NVarChar, 50);
            parameterQuantity.Value = width;
            cmdSelect.Parameters.Add(parameterWidth);

            cnCart.Open();
            cmdSelect.ExecuteNonQuery();
            cnCart.Close();
        }


The agony is that I had all this going very well about a week ago and then I formatted my harddrive without making any copies of the application.
Please, please take a look and tell me what is it that I am doing wrong. Thanks very much.

 
Old July 4th, 2004, 10:37 PM
Authorized User
 
Join Date: Jun 2004
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have got the mistake guys. Sorry to have bothered you. There were a bunch of typos in my class methods. Apologies.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 8 April 29th, 2010 05:56 AM
Input string was not in a correct format. Silfverduk VB.NET 2002/2003 Basics 1 May 20th, 2006 04:58 AM
input string was not in a correct format kunal.net VS.NET 2002/2003 1 October 11th, 2005 12:18 AM
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 2 April 4th, 2005 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.