It means your string is not in double format. when it tried to convert into double, it couldnt and threw error.
Use Double.TryParse.
double d1;
double d2;
double d3;
if(!(Double.TryParse(dt.Rows[i][1].ToString(),out d1)))
return;
if(!(Double.TryParse(dt.Rows[i+1][1].ToString(),out d2)))
return;
if (d1==d2)
{
for (int j = 0; j < dt.Rows.Count - i; j++)
{
Double.TryParse(dt.Rows[i + j][1].ToString(),out d3);
if (d1==d3)
{
....
Tryparse will parse the string to double only if the string contains double value. If its not able to convert, it wont threw error and stop your program. Instead of that it will set value as 0.00 if i try to convert string "s" to double in normal way, it will threw error as you said. But if i use tryparse, it will return me double.MinValue