I have two web pages, one is viewlarger.aspx , another one is
shoppingcart.as px. On the viewlarger.aspx , when clicking "add to cart"
image button, the sub appends the id (passed from another page from a
hyperlink column) into a session. the code is as following:
Private Sub ibtAddtoCart_Cl ick(ByVal sender As System.Object,
ByVal e As System.Web.UI.I mageClickEventA rgs) Handles
ibtAddtoCart.Cl ick
idStr = Session("ids")
pid = Request.QuerySt ring("id")
Dim sb As New StringBuilder(i dStr)
idStr = sb.Append(" ").Append(pid). ToString
Session("ids") = idStr
'Label1.Text = "idStr:" + CType(Session(" ids"), String)
Response.Redire ct("shoppingcar t.aspx")
End Sub
I use a label to test if the session gets the id, it shows me that
this sub works well, each time I click the "add to cart" button, the
id is appended to the session.
then on shoppingcart.as px, in onload, I pick up the id string, call a
function to get the items from the Access database. The function first
pick up all records and fill them into the datatable, then I delete
those datarows which don't match the ids that I pick up from the
session. I bind the datatable to the datagrid. When compile, I got
this error message "Input string was not in a correct format" which
complain the line in the function. Here is the function:
Public Class ShoppingCart
Public Function getCart(ByVal ids As String) As DataTable
Dim conStr As String =
System.Configur ation.Configura tionSettings.Ap pSettings("conS tring")
Dim oleCon As New OleDbConnection (conStr)
Dim cmdStr As String = "Select item_ID, item_name, price,
P_S_T, G_S_T from Item"
Dim oleAdapter As New OleDbDataAdapte r(cmdStr, oleCon)
Dim dsItems As New DataSet()
oleAdapter.Fill (dsItems, "items")
Dim idArr As String() = Split(ids)
Dim dr As DataRow
Dim dt As DataTable = dsItems.Tables( "items")
For Each dr In dt.Rows
Dim id_to_check As Integer = dr.Item("item_I D")
Dim id As String
Dim found As Boolean = False
For Each id In idArr
If (id_to_check = Integer.Parse(i d)) Then
' this line is the red line when compiling'
found = True
End If
Next
If Not found Then
dr.Delete()
End If
Next
Return dt
End Function
in onload, code is like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim cart As New Store.ShoppingC art()
Dim str As String = CType(Session(" ids"), String)
'Dim str As String = "1 3 4" 'if I use this string
instead of using the string from session, no error at all.
Dim dt As DataTable = cart.getCart(st r)
If Not IsPostBack Then
dgCart.DataSour ce = dt.DefaultView
dgCart.DataBind ()
End If
the item_ID in item table in Access, is defined as "Number".
I'm confused with this error message. I have tested the session result
on the viewlarger.aspx , and with a string " 1 3 4". Both are ok. Why
couldn't I use the string got from the session?
If you know the answer to my problem, please help me!
shoppingcart.as px. On the viewlarger.aspx , when clicking "add to cart"
image button, the sub appends the id (passed from another page from a
hyperlink column) into a session. the code is as following:
Private Sub ibtAddtoCart_Cl ick(ByVal sender As System.Object,
ByVal e As System.Web.UI.I mageClickEventA rgs) Handles
ibtAddtoCart.Cl ick
idStr = Session("ids")
pid = Request.QuerySt ring("id")
Dim sb As New StringBuilder(i dStr)
idStr = sb.Append(" ").Append(pid). ToString
Session("ids") = idStr
'Label1.Text = "idStr:" + CType(Session(" ids"), String)
Response.Redire ct("shoppingcar t.aspx")
End Sub
I use a label to test if the session gets the id, it shows me that
this sub works well, each time I click the "add to cart" button, the
id is appended to the session.
then on shoppingcart.as px, in onload, I pick up the id string, call a
function to get the items from the Access database. The function first
pick up all records and fill them into the datatable, then I delete
those datarows which don't match the ids that I pick up from the
session. I bind the datatable to the datagrid. When compile, I got
this error message "Input string was not in a correct format" which
complain the line in the function. Here is the function:
Public Class ShoppingCart
Public Function getCart(ByVal ids As String) As DataTable
Dim conStr As String =
System.Configur ation.Configura tionSettings.Ap pSettings("conS tring")
Dim oleCon As New OleDbConnection (conStr)
Dim cmdStr As String = "Select item_ID, item_name, price,
P_S_T, G_S_T from Item"
Dim oleAdapter As New OleDbDataAdapte r(cmdStr, oleCon)
Dim dsItems As New DataSet()
oleAdapter.Fill (dsItems, "items")
Dim idArr As String() = Split(ids)
Dim dr As DataRow
Dim dt As DataTable = dsItems.Tables( "items")
For Each dr In dt.Rows
Dim id_to_check As Integer = dr.Item("item_I D")
Dim id As String
Dim found As Boolean = False
For Each id In idArr
If (id_to_check = Integer.Parse(i d)) Then
' this line is the red line when compiling'
found = True
End If
Next
If Not found Then
dr.Delete()
End If
Next
Return dt
End Function
in onload, code is like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim cart As New Store.ShoppingC art()
Dim str As String = CType(Session(" ids"), String)
'Dim str As String = "1 3 4" 'if I use this string
instead of using the string from session, no error at all.
Dim dt As DataTable = cart.getCart(st r)
If Not IsPostBack Then
dgCart.DataSour ce = dt.DefaultView
dgCart.DataBind ()
End If
the item_ID in item table in Access, is defined as "Number".
I'm confused with this error message. I have tested the session result
on the viewlarger.aspx , and with a string " 1 3 4". Both are ok. Why
couldn't I use the string got from the session?
If you know the answer to my problem, please help me!