Convert Request.QueryString to Integer

Posted on 2009-04-16
Last Modified: 2012-05-06


Public IDTopico As Integer

I'm trying to assign the QueryString("id") to the IDTopico. I've tryed like this two ways and I get error messages:

IDTopico = Request.QueryString("id")     (Error:"Conversion from string "'1'" to type 'Integer' is not valid.")

or this

IDTopico = ConvertRequest.QueryString("id")    (Error:"Input string was not in a correct format.")

Can someone help me please?


Question by:jppinto
    LVL 9

    Expert Comment

    LVL 33

    Author Comment

    I think that your code is not correct. Int.Parse is not valid code!
    LVL 9

    Assisted Solution

    try Integer.Parse that seems to be equivalent
    LVL 5

    Assisted Solution

    You are using VB?

    Dim idString As [String] = Request.QueryString("id").ToString()
    Dim idNumber As Integer = Convert.ToInt32(idString )

    C# version:
    String idString = Request.QueryString["id"].ToString();
    int idNumber = Convert.ToInt32(idString);

    LVL 33

    Accepted Solution

    I've solved the problem! I've seen the problem. I was using this:

    Response.Redirect("resposta.aspx?id='" & IDTopico &'")  

    to send the id to the other page where I was trying to convert something like "'1'" to integer, instead of "1"... sorry for the trouble that I gave you guys. I will assist both of you for the time that you've spent.

    Again, thanks.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now