473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

"Input string was not in a correct format"

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
ibtAddtoCart.Click
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)
Response.Redirect("shoppingcart.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.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
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.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
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!
Nov 17 '05 #1
0 25842

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Punisher | last post by:
Ok I'm trying to reference a specific node in a tree. TreeNode nodeParentChannel = treeview1.Nodes; It bugs out with this error: Input string was not in a correct format Obviously 1.2 is not...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
2
by: chongo | last post by:
Hi, i'm reading in a bigint value from SQL Server. string s = myReader.ToString()); int intBackColour = System.Convert.ToInt32(s); I'm also reading in other values the same way and it...
3
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. The program uses ADO.NET . The following instruction: Me.cd_insertDataRecord.ExecuteNonQuery() throws this exception: ">>>ProcessDataRecord/...
1
by: James Pose | last post by:
Convert.Int32 fails for "0" but works fine for all other numbers. This does not work on one machine when "0" it works fine on other machines Convert.ToInt32(“0”); gives exception {"Input...
3
by: Pieter Coucke | last post by:
Hi, When a user types a non numeric-value in a numeric column in a DataGridView, and he tries to leave the cell, he gets this "Input string was not in a correct format."-exception. Is there a...
0
by: bnlockwood | last post by:
G'day all, Thank you in advance for anyone that can help. I have a shopping cart datagrid on my c# asp.net page. This is the code: ------------------------------------- <asp:datagrid...
13
by: Jen | last post by:
One user of my application is experiencing an exception "input string not in correct format". But it makes no sense where it is occurring. It is occurring when a string from a textbox ("172") is...
9
muaddubby
by: muaddubby | last post by:
Hi I'm running into a scenario with a DataSet that has a schema loaded into it, tries to then load data (that matches the schema), and fails with a "Input string was not in a correct format"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.