ASP.Net Eval function error: Input string was not in a correct format.

Last Reply on Dec 20, 2017 03:39 AM By Mudassar

Posted on Dec 18, 2017 11:18 AM

hi

I define label in page that save date in persian format like:

1396/02/14

now I want save this date in database so write below code:

DateTime startDate = new DateTime(int.Parse((row.FindControl("lblDate") as Label).Text.Split('/')[0]), int.Parse((row.FindControl("lblDate") as Label).Text.Split('/')[1]), int.Parse((row.FindControl("lblDate") as Label).Text.Split('/')[2]), shamsi);
_cmd.Parameters.AddWithValue("@date", startDate);

but below error happen:

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 98:                     string PriceT = (row.FindControl("LblPriceT") as Label).Text.Trim();
Line 99:                     //string Date = (row.FindControl("lblDate") as Label).Text.Trim();
Line 100:                    DateTime startDate = new DateTime(int.Parse((row.FindControl("lblDate") as Label).Text.Split('/')[0]), int.Parse((row.FindControl("lblDate") as Label).Text.Split('/')[1]), int.Parse((row.FindControl("lblDate") as Label).Text.Split('/')[2]), shamsi);
Line 101:                    _cmd.Parameters.AddWithValue("@date", startDate);

how I can solve this error:

best regards

neda

Posted on Dec 20, 2017 03:39 AM

Here date is not proper. 0001 is not a recognised year in computer