[Solved] Conver.ToInt32 Error: Input string was not in a correct format

Last Reply 21 days ago By pandeyism

Posted 21 days ago

 

cmd.Parameters.AddWithValue("@company_email", (form1.FindControl("c_email") as TextBox).Text.Trim().ToString());  
cmd.Parameters.AddWithValue("@nozzle_lph", (form1.FindControl("nozzle_lph") as TextBox).Text.Trim().ToString());  
cmd.Parameters.AddWithValue("@nozzle_price",Convert.ToInt32((form1.FindControl("nozzle_price") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@lateral_mm", Convert.ToInt32((form1.FindControl("txt_lat_mm") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@lateral_price", Convert.ToInt32((form1.FindControl("txt_lat_price") as TextBox).Text.Trim().ToString()));  
cmd.Parameters.AddWithValue("@submain_mm", Convert.ToInt32((form1.FindControl("txt_smain_mm") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@submain_price", Convert.ToInt32((form1.FindControl("txt_smain_price") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@main_mm", Convert.ToInt32((form1.FindControl("txt_main_mm") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@main_price", Convert.ToInt32((form1.FindControl("txt_main_price") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@Sp_mpump_hp", (form1.FindControl("txt_mpum_hp") as TextBox).Text.Trim()));  
cmd.Parameters.AddWithValue("@Sp_mpump_price", Convert.ToInt32((form1.FindControl("txt_mpump_price") as TextBox).Text.Trim()));  

this is showing the below error,

Server Error in '/' 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 60:             cmd.Parameters.AddWithValue("@lateral_mm", Convert.ToInt32((form1.FindControl("txt_lat_mm") as TextBox).Text.Trim()));
Line 61:             cmd.Parameters.AddWithValue("@lateral_price", Convert.ToInt32((form1.FindControl("txt_lat_price") as TextBox).Text.Trim()));
Line 62:             cmd.Parameters.AddWithValue("@submain_mm", Convert.ToInt32((form1.FindControl("txt_smain_mm") as TextBox).Text.Trim()));
Line 63:             cmd.Parameters.AddWithValue("@submain_price", Convert.ToInt32((form1.FindControl("txt_smain_price") as TextBox).Text.Trim()));
Line 64:             cmd.Parameters.AddWithValue("@main_mm", Convert.ToInt32((form1.FindControl("txt_main_mm") as TextBox).Text.Trim()));

Source File: C:\Users\ait_0207\source\repos\ait0207(sem7)\Test_captcha\test_table_dynamic.aspx.cs    Line: 62 

Stack Trace: 


[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12833139
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +122
   System.Convert.ToInt32(String value) +48
   Test_captcha.test_table_dynamic.sprink_submit_Click(Object sender, EventArgs e) in C:\Users\ait_0207\source\repos\ait0207(sem7)\Test_captcha\test_table_dynamic.aspx.cs:62
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9796134
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +211
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.3815.0

 

You are viewing reply posted by: pandeyism 21 days ago.
Posted 21 days ago Modified on 21 days ago
nid@patel says:
cmd.Parameters.AddWithValue("@submain_mm", Convert.ToInt32((form1.FindControl("txt_smain_mm") as TextBox).Text.Trim()));  

 Check above line of code what value are getting ? Because of you are converting in integer so make sure it should be numeric value.