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>