stuffandthings
03-21-2007, 10:23 AM
Hi, i'm fairly new to this so please bear with me.
I'm attempting to write a simple shopping cart application. I have created a page load event on my products page that creates a db connection, binds the data to a datalist and then calls a function called makeCart() which initialises objDT (datatable) and sets its columns. objDT holds the list of the cart's contents. When required, the user can hit a 'go to checkout' button to go to another page to process the transaction. This works fine, but i have a 'continue shopping' button which when pressed returns the user to the previous page. This then runs the page load event which reinitialises my cart so that it shows empty. Can you tell me how i can check the 'contents' of the session so that i can avoid calling the makeCart() function.
I have tried using 'If (Session("Cart") is System.DBNull.Value) Then' but this didn't work. Any help would be very much appreciated.
Here is my code for the troublesome section:
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dbconn, sql, dbcomm, dbread
dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data/consumables.mdb"))
dbconn.Open()
sql = "SELECT * FROM tblconsumables ORDER BY consCode"
dbcomm = New OleDbCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
consumablesList.DataKeyNames = New String() {"consID"}
' bind the reader to the datalist
consumablesList.DataSource = dbread
consumablesList.DataBind()
' close the reader
dbread.Close()
makeCart()
CheckCart()
End If
End Sub
Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("Code", GetType(String))
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))
Session("Cart") = objDT
End Function
I'm attempting to write a simple shopping cart application. I have created a page load event on my products page that creates a db connection, binds the data to a datalist and then calls a function called makeCart() which initialises objDT (datatable) and sets its columns. objDT holds the list of the cart's contents. When required, the user can hit a 'go to checkout' button to go to another page to process the transaction. This works fine, but i have a 'continue shopping' button which when pressed returns the user to the previous page. This then runs the page load event which reinitialises my cart so that it shows empty. Can you tell me how i can check the 'contents' of the session so that i can avoid calling the makeCart() function.
I have tried using 'If (Session("Cart") is System.DBNull.Value) Then' but this didn't work. Any help would be very much appreciated.
Here is my code for the troublesome section:
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dbconn, sql, dbcomm, dbread
dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("App_Data/consumables.mdb"))
dbconn.Open()
sql = "SELECT * FROM tblconsumables ORDER BY consCode"
dbcomm = New OleDbCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
consumablesList.DataKeyNames = New String() {"consID"}
' bind the reader to the datalist
consumablesList.DataSource = dbread
consumablesList.DataBind()
' close the reader
dbread.Close()
makeCart()
CheckCart()
End If
End Sub
Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("Code", GetType(String))
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))
Session("Cart") = objDT
End Function