Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2006, 03:35 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default input string not in correct format

hi all

i am trying to perform delete operation for shopping cart.
i am getting the error "input string not in correct format.
can anyone please tel me where have i gone wrong.
given below is the code

the class which contains cartoperation shopcart1.vb
 Public Sub DeleteItem(ByVal CartID As String, ByVal ProductID As Integer)

            Dim con As New SqlConnection("")
            Dim cmd As New SqlCommand
            cmd.Connection = con
            cmd.CommandText = "delete from ShoppingCart where CartID=@cartid and ProductID=@prodid"

            Dim p1 As New SqlParameter("@cartid", CartID)
            Dim p2 As New SqlParameter("@prodid", ProductID)

            cmd.Parameters.Add(p1)
            cmd.Parameters.Add(p2)

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()

        End Sub

cart.aspx page
 Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid1.DeleteCommand

        Dim shopcart3 As ShoppingCart.shopcart = New ShoppingCart.shopcart
        shopcart3.DeleteItem(Session.SessionID, Integer.Parse(e.Item.Cells(0).Text))

        FillCartFromDB()

    End Sub

Function FillCartFromDB()

        Dim ds As New DataSet
        ds = ShoppingCart.shopcart.GetAll(Session.SessionID)

        DataGrid1.DataSource = ds
        DataGrid1.DataBind()

        Button1_Click(Nothing, Nothing)


    End Function

thanks in advance

 
Old October 30th, 2006, 03:42 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What method is the error being raised from?

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 30th, 2006, 03:44 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 83:
Line 84: Dim shopcart3 As ShoppingCart.shopcart = New ShoppingCart.shopcart
Line 85: shopcart3.DeleteItem(Session.SessionID, Integer.Parse(e.Item.Cells(0).Text))
Line 86:
Line 87:

Source File: C:\Inetpub\wwwroot\ShoppingCart3VB\MyCart.aspx.vb Line: 85

Stack Trace:


[FormatException: Input string was not in a correct format.]
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +0
   System.Int32.Parse(String s) +38
   ShoppingCart3VB.MyCart.DataGrid1_DeleteCommand(Obj ect source, DataGridCommandEventArgs e) in C:\Inetpub\wwwroot\ShoppingCart3VB\MyCart.aspx.vb: 85
   System.Web.UI.WebControls.DataGrid.OnDeleteCommand (DataGridCommandEventArgs e) +110
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e) +589
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e) +100
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +120
   System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1292





 
Old October 30th, 2006, 03:50 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Judging from your stack trace the error is being directly thrown from this line

shopcart3.DeleteItem(Session.SessionID, Integer.Parse(e.Item.Cells(0).Text))

as opposed to the actual DeleteItem method thorwing the error. My suggestion would be to 1)check that SessionID has a value associated with it and 2) see if the data you are trying to parse to an integer is correct.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 30th, 2006, 03:59 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you please tel me how can we check for the value existence

thanks

 
Old October 30th, 2006, 04:03 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Step through your code in the Visual Studio debugger? Response.Write the values to the screen, etc.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 30th, 2006, 04:10 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i wrote in script as
sub page_load(....)
response.write("ProductID")
response.write("Session.sessionid")
end sub

when i executed, i am getting a " in the result, not any values

whatshall i do?
can you please tel?

 
Old October 30th, 2006, 04:18 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Those commands should, literally, write ProductID and Session.SessionID to the page since you are passing them as strings to the response object as opposed to the references.

Response.Write(productID & " " & Session.SessionID)

Also, read this article since you are obviously using the sessionID to delete stuff from a database:
http://forums.asp.net/7504/ShowPost.aspx

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 30th, 2006, 05:02 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i tried with your suggestion
i am getting the sessionid,
the product id is also getting
then what can be the reason for the error?
can you please tel ?
thanks
 
Old October 30th, 2006, 05:15 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I have no idea, it has to do with your program flow, somewhere along the line you are not correctly setting the product ID.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature





Similar Threads
Thread Thread Starter Forum Replies Last Post
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 8 April 29th, 2010 05:56 AM
Input string was not in a correct format. Silfverduk VB.NET 2002/2003 Basics 1 May 20th, 2006 04:58 AM
input string was not in a correct format kunal.net VS.NET 2002/2003 1 October 11th, 2005 12:18 AM
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 2 April 4th, 2005 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.