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

Last Reply one year ago By Mudassar

Posted one year ago

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 one year ago

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