locked
Input string was not in a correct format. RRS feed

  • Question

  • hi, anyone who can help me, when i build my project it is succeeded but when i run it and put some value it has an error pointing to this line.
    
                        Xrm.new_businesspermit bp = con.FindBP(con.CreateApplicant(this.txtDTI.Text, this.txtReference.Text, this.txtTIN.Text, this.txtCTC.Text, this.txtentity.Text, Int32.Parse (this.ddltypeofpermit.SelectedValue), Int32.Parse (this.ddlOwnership.SelectedValue), Int32.Parse(this.ddlpayment.SelectedValue), Int32.Parse(this.ddlamendments.SelectedValue), Int32.Parse(this.ddlTypeOfOrg.SelectedValue)));
    
    
    and the error is "Input string was not in a correct format."
    hope someone can help me on this . 
    thanks 
    Thursday, February 2, 2012 3:49 AM

Answers

  • there is an Int32.Parse that receive a value that is not an integer...probably a null string

    for example the folowing code throws the same error

    class Program
        {
            static void Main(string[] args)
            {
                var myval = "";
                int.Parse(myval);
            }
        }
    

    Hope this helps.

    • Proposed as answer by rkm1980 Thursday, February 2, 2012 4:31 AM
    • Marked as answer by Lie You Monday, February 6, 2012 7:35 AM
    Thursday, February 2, 2012 4:02 AM

All replies

  • there is an Int32.Parse that receive a value that is not an integer...probably a null string

    for example the folowing code throws the same error

    class Program
        {
            static void Main(string[] args)
            {
                var myval = "";
                int.Parse(myval);
            }
        }
    

    Hope this helps.

    • Proposed as answer by rkm1980 Thursday, February 2, 2012 4:31 AM
    • Marked as answer by Lie You Monday, February 6, 2012 7:35 AM
    Thursday, February 2, 2012 4:02 AM
  • Hi twinkle0903,

     

     If you don't want compile environment to prompt so unamiable message to you,you can refer to int.TryParse for more secure conversation.For more information,you can read the following link :

    http://msdn.microsoft.com/en-us/library/f02979c7.aspx

     

     

    Sincerely,

    Jason Wang

     

    Thursday, February 2, 2012 7:34 AM
  • check your string is not null when you convert to int. other wise use use parse method.

    http://www.java-forums.org/forum.php

    • Proposed as answer by Svexo Thursday, February 2, 2012 2:51 PM
    • Unproposed as answer by Svexo Thursday, February 2, 2012 2:51 PM
    • Proposed as answer by Anil Sachin Thursday, February 2, 2012 6:13 PM
    • Unproposed as answer by Anil Sachin Thursday, February 2, 2012 6:14 PM
    • Edited by janveeshenoy Thursday, September 13, 2012 9:10 PM
    Thursday, February 2, 2012 2:46 PM
  •  your error was most likely caused because the string was empty or contained something not numeric (letter or special char)

    The best way imo to convert a string to an int would be as followed :

     

    string number  = "555";
    int convertednumber;
    
    if(int.TryParse(number,out convertednumber))
    {
        //Handle Succes
    }
    else 
    {
        // Failed to convert
       // Handle fail
    }
    


     


    • Edited by Svexo Thursday, February 2, 2012 2:56 PM
    Thursday, February 2, 2012 2:53 PM