Subject: Input string was not in a correct format
Posted By: Jeremy Goldman Post Date: 12/15/2003 12:47:04 PM
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("ConnString"))
    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
Reply By: stu9820 Reply Date: 12/15/2003 1:00:48 PM
Dim qsPage As String = Request.QueryString("page")

Try changing it to Integer

Reply By: Jeremy Goldman Reply Date: 12/15/2003 11:10:20 PM
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...

Reply By: planoie Reply Date: 12/16/2003 6:44:51 AM
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.
Reply By: Jeremy Goldman Reply Date: 12/16/2003 9:47:45 AM
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..
Reply By: stu9820 Reply Date: 12/16/2003 10:10:29 AM
Let's see your Stored Procedure.

Reply By: planoie Reply Date: 12/16/2003 10:33:48 AM
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.
Reply By: Jeremy Goldman Reply Date: 12/16/2003 4:52:58 PM
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?

Reply By: Jeremy Goldman Reply Date: 12/16/2003 5:00:22 PM
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


Reply By: Imar Reply Date: 12/16/2003 5:03:48 PM
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.

Go to topic 7622

Return to index page 985
Return to index page 984
Return to index page 983
Return to index page 982
Return to index page 981
Return to index page 980
Return to index page 979
Return to index page 978
Return to index page 977
Return to index page 976