when I tried to compare two lines, it shows error like this:
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.
My code is:
if (i != (dt.Rows.Count - 1))
{
if (Convert.ToDouble(dt.Rows[i][1].ToString()) ==
Convert.ToDouble(dt.Rows[i + 1][1].ToString())) // this is the wrong line
{
for (int j = 0; j < dt.Rows.Count - i; j++)
{
if (Convert.ToDouble(dt.Rows[i][1].ToString()) ==
Convert.ToDouble(dt.Rows[i + j][1].ToString()))
I’ve tried also to change the ToDouble to ToInt32, but it just doesn’t work.
could anyone tell me, what does this error message mean?
many thanks!!!
That error means that it could not be converted to a
double. Attach a debugger and look at the value that it’s trying to convert and see why it’s not a valid number.You could also look at using the
TryParsemethods so that an exception isn’t thrown when the value can’t be converted.