Cast QueryString!

A

Adam J Knight

Hi all,

I am having trouble converting query string values to int like so:

intValue = (int) Request.QueryString["QuestionID"];

I keep getting the error, cannot convert string to int...

How can i do this??

Cheers,
Adam
 
E

Eliyahu Goldin

intValue = System.Convert.ToInt32 (Request.QueryString["QuestionID"]);

Eliyahu
 
H

Hans Kesting

Hi all,
I am having trouble converting query string values to int like so:

intValue = (int) Request.QueryString["QuestionID"];

I keep getting the error, cannot convert string to int...

How can i do this??

Cheers,
Adam

You can only *cast* to int if you have:
1) a numerical type (double, short, ..)
2) an int boxed as object

Request.QueryString returns a string, which you can convert to an int
with Int32.Parse(..). Note: it will throw an exception if the string
can't be converted to an int. You might want to catch this.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top