 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 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
|
|
|
|

December 15th, 2003, 01:47 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Input string was not in a correct format
I have no idea what the problem is here - especially because this code seemingly worked a few hours ago (though maybe I changed something small).
I'm trying to read from the querystring an integer value. Based on the querystring's content, I do a lookup in the database and present a different page to the user. For instance, http://localhost/wjer03/content.aspx?page=1 uses a Stored Proc to Select the record where the contentID is '1'. However, I keep getting 'Input string was not in a correct format'. Here's my code - any ideas?
Public Sub DisplayContent()
Dim qsPage As String = Request.QueryString("page")
Dim cn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnString"))
Dim cmdContent As SqlCommand = New SqlCommand("ViewContent", cn)
cmdContent.CommandType = CommandType.StoredProcedure
cmdContent.Parameters.Add("@pageRequested", SqlDbType.Int).Value() = qsPage
cn.Open()
Dim rdrContent As SqlDataReader
listContent.DataSource = cmdContent.ExecuteReader()
listContent.DataBind()
cn.Close()
End Sub
|
|

December 15th, 2003, 02:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Dim qsPage As String = Request.QueryString("page")
Try changing it to Integer
|
|

December 16th, 2003, 12:10 AM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by stu9820
Dim qsPage As String = Request.QueryString("page")
Try changing it to Integer
|
I tried that earlier, and that didn't work - plus, querystring info is always supposed to be initially captured as a string. Also, it was working just fine initially calling qsPage as a string, so the problem needs to be elsewhere...
|
|

December 16th, 2003, 07:44 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Can you post the integer conversion you tried that you say didn't work? If the parameter in SQL is an INT, then just sending in the QS value directly won't work regardless of the fact that you don't get a design-time or build error. You need to convert.
cmdContent.Parameters.Add("@pageRequested", SqlDbType.Int).Value() = CType(qsPage, Integer)
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

December 16th, 2003, 10:47 AM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by planoie
Can you post the integer conversion you tried that you say didn't work? If the parameter in SQL is an INT, then just sending in the QS value directly won't work regardless of the fact that you don't get a design-time or build error. You need to convert.
cmdContent.Parameters.Add("@pageRequested", SqlDbType.Int).Value() = CType(qsPage, Integer)
Work smarter, not harder.
|
I've tried all sorts of conversions on that line, including the one you just suggested - but all it does it give me the same error, this time on that cmdContent.Parameters.Add line (formerly it gave me the error on the ExecuteReader() line.
I'm beginning to think this might be a bug in the framework...it simply won't let me convert the freakin' data type..
|
|

December 16th, 2003, 11:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Let's see your Stored Procedure.
|
|

December 16th, 2003, 11:33 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Is the error you are getting coming from SQL or .net? You provided the error text, but didn't specify the source. This has a large impact on our suggestions.
Is the data type for @pageRequested in the sproc correct? Is the use of that var within the sproc correct?
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

December 16th, 2003, 05:52 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It looks like the error is coming from .NET, not the sproc. I am getting the error on the ExecuteReader() line; to isolate the problem, I removed the sproc and threw the SQL query into the asp.net code, to no avail.
The @pageRequested var is called as an Int, so that shouldn't be a problem...I would be so bold as to say there is no way the problem can be in the sproc.
Is it possible this is a bug with DataReaders?
|
|

December 16th, 2003, 06:00 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by stu9820
Let's see your Stored Procedure.
|
Here it is:
Here's my Stored Procedure, it looks fine to me:
CREATE PROCEDURE dbo.ViewContent
(
@PageRequested NVarChar
)
As
(
SELECT * FROM siteContent WHERE contentID = @PageRequested
)
GO
|
|

December 16th, 2003, 06:03 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, it looks fine but it expects an NVarchar, not an Int. So you should change:
("@pageRequested", SqlDbType.Int
to
("@pageRequested", SqlDbType.NVarChar
I was actually going to ask what those parentheses were doing after the Value when your message with the Sproc came in. Instead, try to create a parameter explicitly, assign its value and then add it to the Parameters collection.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |