Convert Querystring to Int

Posted on 2008-02-11
Medium Priority
Last Modified: 2012-06-27
I need to receive a querystring, convert it to an integer and then pass it as a parameter to a stored procedure.  I have tried:

    ID = int.Parse(Request.QueryString["ID"]);
    int ID = int.Parse(Request.QueryString["ID"]);
    int ID = int.Parse(HttpContext.Current.Request.QueryString["ID"]);

In each case the application returns an error that the data type could not be converted.
Question by:cgcmq
LVL 22

Expert Comment

ID: 20866116

parse functions require string format.
LVL 22

Accepted Solution

p_davis earned 2000 total points
ID: 20866117
sorry ToString();

Expert Comment

ID: 20866155
Perhaps the following would work:

 int ID = Convert.ToInt32(Request.QueryString.Get("ID"));
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Author Comment

ID: 20866162
I love it when the answer is so easy.

ID = int.Parse(Request.QueryString["ID"]).ToString();
LVL 23

Expert Comment

by:Ashish Patel
ID: 20866165
as you are again converting the stuff back to ToString() just use

ID = Request.QueryString["ID"].ToString();

Author Closing Comment

ID: 31429778
It drives me crazy.  I looked at 3 different references and non of them mentioned that.  

I think that I am going to go back to classic ASP before I lose my mind.

Thanks for the tip.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month4 days, 14 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question