none
Input string was not in a correct format.

    Question

  • When i try to compile the code i got the following error message !

    Server Error in '/LandMangement' Application.

    Input string was not in a correct format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.FormatException: Input string was not in a correct format.

    Source Error:

    Line 100:        if (SaveResidentialbttn.Text == "Save")
    Line 101: {
    Line 102: retVal = ResiMaster.Insert( ddlSector.SelectedValue,txtBlock.Text,txtPlot.Text,Convert.ToDateTime( txtEntryDate.Text),
    Line 103: txtLocation.Text,txtCatagory.Text,Convert.ToInt32(txtGroundRent.Text),txtPerPeriod.Text,
    Line 104: txtGroundRentDesc.Text,ddlResi.SelectedValue,ddlShopAllowed.SelectedValue,ddlIfResdenditial.SelectedValue,

    Source File: e:\LandMangement\Residential.aspx.cs    Line: 102

    Stack Trace:

    [FormatException: Input string was not in a correct format.]
    System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2755599
    System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +112
    System.Convert.ToInt32(String value) +68
    Residential.SaveResidentialbttn_Click(Object sender, EventArgs e) in e:\LandMangement\Residential.aspx.cs:102
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

    protected void SaveResidentialbttn_Click(object sender, EventArgs e) 
        { 
            int retVal = 0; 
            //Insert 
            if (SaveResidentialbttn.Text == "Save"
            { 
                retVal = ResiMaster.Insert(  ddlSector.SelectedValue,txtBlock.Text,txtPlot.Text,Convert.ToDateTime( txtEntryDate.Text), 
                                             txtLocation.Text,txtCatagory.Text,Convert.ToInt32(txtGroundRent.Text),txtPerPeriod.Text, 
                                             txtGroundRentDesc.Text,ddlResi.SelectedValue,ddlShopAllowed.SelectedValue,ddlIfResdenditial.SelectedValue, 
                                             ddlIfNotResidential.SelectedValue,txtAllotmentNo.Text,Convert.ToDateTime(txtAllotDate.Text),ddlPreviouslyAlloted.SelectedValue, 
                                             txtFavour.Text, Convert.ToDateTime(txtDateOfExecution.Text),Convert.ToDateTime(txtDateOfRegistration.Text),txtCoOptHousingSociaty.Text,  
                                             txtSociatyreg.Text,Convert.ToInt32( txtSalami.Text),Convert.ToInt32( txtInterestPaid.Text ),Convert.ToInt32(txtBPValue.Text), 
                                             Convert.ToInt32( txtTotalValue.Text),Convert.ToInt32(txtBalenceDue.Text),Convert.ToDateTime(txtDateOfpossession.Text),txtCertificateNo.Text , 
                                             txtTypeOfPossession.Text,Convert.ToInt32(txtGroundRentPaidUpto.Text),Convert.ToInt32(txtGroundRentAmount.Text),Convert.ToInt32(TxtBalenceDueifAny.Text), 
                                             txtPlanSubmitted.Text,Convert.ToDateTime(txtOriginalDate.Text),txtNo.Text, txtRemarks.Text, 
                                             txtPlanSanctioned.Text,Convert.ToDateTime(txtDOSanctioned.Text),txtDOSanctionedNo.Text, Convert.ToDateTime(txtDORevisedSanction.Text), 
                                             txtDORevisedSanctionNo.Text,txtRemarksDORevised.Text,ddlTenYearsExpired.SelectedValue, Convert.ToDateTime(txtOriginalDate1.Text), 
                                             txttxtOriginalDate1.Text,Convert.ToDateTime(txtReviseddate1.Text), txtNoReviseddate1.Text, txtREmarksReviseddate1.Text,  
                                             txtStoreysPlanned.Text,urm_const_status.Text,txtNoofStorageComplete.Text,txtConstructionStroge.Text, 
                                             txtConstructionRemarks.Text,txtCGGrantedFloorwise.Text,ddlCommercialUtilisationDetails.SelectedValue,txtOtherUtilisation.Text , 
                                             ddlPublicUtilisationDetails.SelectedValue,txtOtherUtilisation1.Text,txtIndustrialutilisation.Text,ddlPlotLeaseOwnedBy.SelectedValue ); 
                 
                ResTableDataBind(); 
                ImageOk.Visible = true
                Msg.Text = "New Record Insert Sucessfully"
                ClearMain(); 
     
            } 

    Please Help
    Thanks
    Thursday, March 05, 2009 8:48 AM

Answers

  • Before you use Convert.Int32 make sure that the string you are passing is a number.

    Alternatively use Int.TryParse which wont throw any exception.

    Thanks, A.m.a.L
    • Proposed as answer by Kenky Dude Friday, March 06, 2009 5:59 AM
    • Marked as answer by Guo Surfer Monday, March 09, 2009 10:43 AM
    Thursday, March 05, 2009 9:15 AM
  • DateTime.TryParse() or DateTime.TryParseExact()
    • Proposed as answer by Matthew Watson Thursday, March 05, 2009 9:51 AM
    • Marked as answer by Guo Surfer Monday, March 09, 2009 10:44 AM
    Thursday, March 05, 2009 9:51 AM

All replies

  • Before you use Convert.Int32 make sure that the string you are passing is a number.

    Alternatively use Int.TryParse which wont throw any exception.

    Thanks, A.m.a.L
    • Proposed as answer by Kenky Dude Friday, March 06, 2009 5:59 AM
    • Marked as answer by Guo Surfer Monday, March 09, 2009 10:43 AM
    Thursday, March 05, 2009 9:15 AM
  • I change the code for Convert.ToInt32(Something.text) to Int32.Parse(Something.text)
    but it shows again

    Input string was not in a correct format.

    Thursday, March 05, 2009 9:23 AM
  • Int.TryParse
    Thanks, A.m.a.L
    • Proposed as answer by Kenky Dude Friday, March 06, 2009 5:59 AM
    • Unproposed as answer by Guo Surfer Monday, March 09, 2009 10:43 AM
    Thursday, March 05, 2009 9:29 AM
  • and for datetime ?
    • Proposed as answer by Kenky Dude Friday, March 06, 2009 5:59 AM
    • Unproposed as answer by Guo Surfer Monday, March 09, 2009 10:43 AM
    Thursday, March 05, 2009 9:46 AM
  • DateTime.TryParse() or DateTime.TryParseExact()
    • Proposed as answer by Matthew Watson Thursday, March 05, 2009 9:51 AM
    • Marked as answer by Guo Surfer Monday, March 09, 2009 10:44 AM
    Thursday, March 05, 2009 9:51 AM