Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 September 8th, 2004, 07:58 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default ShoppingCart problem

Hi,

I have a shopping cart page same as ShoppingCart.aspx.
In the store the user can select whether to calculate the price according to yards or meters.
I wrote a stored procedure that checks to see whether the user selected yards or something else.
Then I have a component that calls the stored procedure as follows:
<code>
 Public Function GetItems(ByVal cartID As String, ByVal Yards As String) As SqlDataReader

        ' Create Instance of Connection and Command Object
        Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
        Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList", myConnection)

        ' Mark the Command as a SPROC
        myCommand.CommandType = CommandType.StoredProcedure

        ' Add Parameters to SPROC
        Dim parameterCartID As SqlParameter = New SqlParameter("@CartID", SqlDbType.NVarChar, 50)
        parameterCartID.Value = cartID
        myCommand.Parameters.Add(parameterCartID)

        Dim parameterYards As SqlParameter = New SqlParameter("@yards", SqlDbType.NVarChar, 50)
        parameterYards.Value = Yards
        myCommand.Parameters.Add(parameterYards)


        ' Execute the command
        myConnection.Open()
        Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)

        ' Return the datareader result
        Return result

    End Function
</code>


The sub PopulateShoppingCartList in aspx.vb uses the function above. PopulateShoppingCartList is called on page load and after the user hits the Update ShoppingCart button. When I use hardcode obviously it works but i need to do it w/o hardcode and i'm not sure how. How do I let the stored procedure know whether the user selected yards or something from the dropdownlist in the datagrid?
<code>

 Sub PopulateShoppingCartList()

        Dim cart As Components.ShoppingCartDB = New Components.ShoppingCartDB

        ' Obtain current user's shopping cart ID
        Dim cartId As String = cart.GetShoppingCartId()

        ' If no items, hide details and display message
        If cart.GetItemCount(cartId) = 0 Then
            DetailsPanel.Visible = False
            MyError.Text = "No items in basket"
        Else
            ' Databind Gridcontrol with Shopping Cart Items
           <b> MyList.DataSource = cart.GetItems(cartId, "yards")</b>
            MyList.DataBind()

            'Update Total Price Label
            lblTotal.Text = String.Format("{0:c}", cart.GetTotal(cartId))
        End If

    End Sub
</code>






Similar Threads
Thread Thread Starter Forum Replies Last Post
ShoppingCart is not a member of ProfileCommon sstuber BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 May 21st, 2008 04:55 PM
ShoppingCart.aspx.cs - System.FormatException ??? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 16th, 2008 01:00 AM
ShoppingCart: SerializeAs XML watxu BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 2nd, 2007 03:04 PM
how to use shoppingcart without profile? hertendreef ASP.NET 2.0 Basics 6 January 11th, 2007 05:16 AM
Err in ShoppingCart.aspx Blueman137 ASP.NET 1.0 and 1.1 Basics 0 March 19th, 2004 09:18 PM





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