|
Subject:
|
input string not in correct format
|
|
Posted By:
|
sarah lee
|
Post Date:
|
10/30/2006 2:35:59 PM
|
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
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/30/2006 2:42:36 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
10/30/2006 2:44:18 PM
|
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(Object 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(Object source, EventArgs e) +589 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +100 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138 System.Web.UI.Page.ProcessRequestMain() +1292
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/30/2006 2:50:13 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
10/30/2006 2:59:07 PM
|
can you please tel me how can we check for the value existence
thanks
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/30/2006 3:03:51 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
10/30/2006 3:10:22 PM
|
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?
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/30/2006 3:18:50 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
10/30/2006 4:02:54 PM
|
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
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/30/2006 4:15:32 PM
|
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
|
|
Reply By:
|
sarah lee
|
Reply Date:
|
10/30/2006 4:18:10 PM
|
ok thanks for all ur help so far
|