By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

"Input string was not in a correct format"

P: n/a
I have two web pages, one is viewlarger.aspx, another one is
shoppingcart.aspx. 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_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles
idStr = Session("ids")
pid = Request.QueryString("id")
Dim sb As New StringBuilder(idStr)
idStr = sb.Append(" ").Append(pid).ToString
Session("ids") = idStr
'Label1.Text = "idStr:" + CType(Session("ids"), String)
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.aspx, 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.Configuration.ConfigurationSettings.AppSett ings("conString")
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 OleDbDataAdapter(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_ID")
Dim id As String
Dim found As Boolean = False
For Each id In idArr
If (id_to_check = Integer.Parse(id)) Then
' this line is the red line when compiling'
found = True
End If
If Not found Then
End If
Return dt
End Function

in onload, code is like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cart As New Store.ShoppingCart()
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(str)

If Not IsPostBack Then
dgCart.DataSource = dt.DefaultView
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!
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.