Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
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
 
Old December 15th, 2003, 01:47 PM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Jeremy Goldman
Default 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
 
Old December 15th, 2003, 02:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Dim qsPage As String = Request.QueryString("page")

Try changing it to Integer

 
Old December 16th, 2003, 12:10 AM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Jeremy Goldman
Default

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...

 
Old December 16th, 2003, 07:44 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
 
Old December 16th, 2003, 10:47 AM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Jeremy Goldman
Default

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..
 
Old December 16th, 2003, 11:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Let's see your Stored Procedure.

 
Old December 16th, 2003, 11:33 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
 
Old December 16th, 2003, 05:52 PM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Jeremy Goldman
Default

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?

 
Old December 16th, 2003, 06:00 PM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Jeremy Goldman
Default

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


 
Old December 16th, 2003, 06:03 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.





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
"Input string was not in a correct format." keane Pro VB.NET 2002/2003 1 December 18th, 2004 08:45 PM





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