Click here to Skip to main content
15,898,373 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Lifecycle question Pin
MBursill15-May-07 10:26
MBursill15-May-07 10:26 
GeneralRe: Lifecycle question Pin
Uwe Keim15-May-07 17:56
sitebuilderUwe Keim15-May-07 17:56 
GeneralRe: Lifecycle question Pin
MBursill16-May-07 7:56
MBursill16-May-07 7:56 
QuestionTreeView needs client side code... Pin
just3ala215-May-07 8:45
just3ala215-May-07 8:45 
QuestionAbout Ajax Pin
Aaanand15-May-07 6:44
Aaanand15-May-07 6:44 
AnswerRe: About Ajax Pin
Not Active15-May-07 7:56
mentorNot Active15-May-07 7:56 
AnswerRe: About Ajax Pin
Christian Graus15-May-07 13:18
protectorChristian Graus15-May-07 13:18 
QuestionProblems with data Pin
TAK7815-May-07 5:40
TAK7815-May-07 5:40 
I have a database in which I store the items that a customer added to the shoppingcart. Now I try to get the data and put it into the shoppingcart when the user loggs back in and there were items he didn't purchased yet but left in cart last time he was logged.
It will display the right quantity of each product, but it shows the Name and price of last recieved product in my ShoppingCart display on all products.
Here is code I have so far for getting items from DB and adding to ShoppingCart:



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Membership.GetUser() Is Nothing Then
StoreManager.ShoppingCart.UserID = Membership.GetUser().UserName
If Not Session("Logged") Then
StoreDB.GetShoppingCart(Membership.GetUser().UserName)
Session("Logged") = True
End If
Else
HttpContext.Current.Session("ShoppingCart") = New ShoppingCart()
StoreManager.ShoppingCart.UserID = ""
Session("Logged") = False
End If
End Sub


Public Shared Sub GetShoppingCart(ByVal userID As String)

Try
Using myCon As New SqlConnection(AppConnection.ConnectionString)

Dim myCom As SqlCommand = New SqlCommand("sprocGetShoppingCartItems", myCon)
myCom.CommandType = CommandType.StoredProcedure
myCom.Parameters.AddWithValue("@cartID", userID)

Dim prod As Product = New Product
Dim qty As Integer = 0

myCon.Open()

Using myRd As SqlDataReader = myCom.ExecuteReader(CommandBehavior.CloseConnection)

While myRd.Read()

prod.CategorieID = myRd.GetInt32(myRd.GetOrdinal("CategorieID"))
prod.ProductID = myRd.GetInt32(myRd.GetOrdinal("ProductID"))
prod.ProductName = myRd.GetString(myRd.GetOrdinal("ProductName"))
prod.ProductPrice = myRd.GetDecimal(myRd.GetOrdinal("ProductPrice"))
prod.ProductMini = myRd.GetString(myRd.GetOrdinal("ProductImage"))
prod.Qty = myRd.GetInt32(myRd.GetOrdinal("Quantity"))

MsgBox("Adding: " & prod.ProductName)
StoreManager.ShoppingCart.AddDB(prod, prod.Qty)
End While
myRd.Close()

End Using
End Using
Catch ex As Exception
' error handling set in Global.asax and web.config
Throw
End Try

End Sub


'Part of my ShoppingCart Class:

Public Class ShoppingCart

Private _items As List(Of OrderedProducts) = New List(Of OrderedProducts)

Public Sub New()
End Sub

Public Sub AddDB(ByVal product As Product, ByVal qty As Integer)
Dim orderedProd As OrderedProducts = New OrderedProducts(product, qty)
_items.Add(orderedProd)
End Sub

End Class

Public Shared ReadOnly Property ShoppingCart() As ShoppingCart
Get
If HttpContext.Current.Session("ShoppingCart") Is Nothing Then
HttpContext.Current.Session("ShoppingCart") = New ShoppingCart()
End If
Return CType(HttpContext.Current.Session("ShoppingCart"), ShoppingCart)
End Get
End Property



QuestionUK/GB Dates Pin
Aaron Hudson15-May-07 5:29
Aaron Hudson15-May-07 5:29 
AnswerRe: UK/GB Dates Pin
-Dr_X-15-May-07 5:35
-Dr_X-15-May-07 5:35 
GeneralRe: UK/GB Dates Pin
Guffa15-May-07 15:10
Guffa15-May-07 15:10 
AnswerRe: UK/GB Dates Pin
Christian Graus15-May-07 13:19
protectorChristian Graus15-May-07 13:19 
QuestionGridView Problem Pin
Bajrang Singh15-May-07 5:29
Bajrang Singh15-May-07 5:29 
QuestionRe: GridView Problem Pin
Venkatesh Mookkan15-May-07 18:22
Venkatesh Mookkan15-May-07 18:22 
AnswerRe: GridView Problem [modified] Pin
Bajrang Singh15-May-07 19:55
Bajrang Singh15-May-07 19:55 
GeneralRe: GridView Problem Pin
Venkatesh Mookkan15-May-07 22:13
Venkatesh Mookkan15-May-07 22:13 
GeneralRe: GridView Problem Pin
Bajrang Singh16-May-07 1:25
Bajrang Singh16-May-07 1:25 
QuestionGridView columns HeaderText from a function Pin
-Dr_X-15-May-07 5:27
-Dr_X-15-May-07 5:27 
AnswerRe: GridView columns HeaderText from a function Pin
Venkatesh Mookkan15-May-07 18:26
Venkatesh Mookkan15-May-07 18:26 
QuestionUser Control Properties Best Practices Pin
john202115-May-07 5:20
john202115-May-07 5:20 
QuestionHttpHandler for *.asp Pin
eggsovereasy15-May-07 5:13
eggsovereasy15-May-07 5:13 
Questionplaying video files Pin
Rahul Babu15-May-07 4:06
Rahul Babu15-May-07 4:06 
AnswerRe: playing video files Pin
Uwe Keim15-May-07 10:05
sitebuilderUwe Keim15-May-07 10:05 
QuestionForms Authentication Cookie expiration problem. Pin
hai_venkatesh15-May-07 3:36
hai_venkatesh15-May-07 3:36 
AnswerRe: Forms Authentication Cookie expiration problem. Pin
kubben15-May-07 3:58
kubben15-May-07 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.