Link to home
Start Free TrialLog in
Avatar of cgcmq
cgcmqFlag for Canada

asked on

Convert Querystring to Int

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.
Avatar of p_davis
p_davis

Request.QueryString["ID"].ToString

parse functions require string format.
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perhaps the following would work:

 int ID = Convert.ToInt32(Request.QueryString.Get("ID"));
Avatar of cgcmq

ASKER

I love it when the answer is so easy.

ID = int.Parse(Request.QueryString["ID"]).ToString();
as you are again converting the stuff back to ToString() just use

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

ASKER

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.