Conversion from string "" to type 'Integer' is not valid.

Posted on 2006-04-24
Last Modified: 2008-01-09
In an update function for my GridView, I have the following:

Dim intBudget As Integer = CType(gvr.FindControl("txtBudget"), TextBox).Text.Trim()

I get the error: An exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll but was not handled in user code

Additional information: Conversion from string "" to type 'Integer' is not valid.

What's weird is that I've used this format before...not sure why now it's throwing an error in my new application.  I see that I am trying to set an integer to a Text value so how do I CType this to an Integer equivilant?
Question by:dba123
    LVL 5

    Accepted Solution

    You need to convert your string in your textbox to an integer with something like this:

    Dim intBudget As Integer
      intBudget = CType(CType(gvr.FindControl("txtBudget"), TextBox).Text.Trim(),Int32)
      intBudget = 0
    End Try
    LVL 1

    Author Comment

    ahh, I see, didn't know there was yet another param option at the end like that.  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

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    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…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now