val = val + (string)dataGridView1.Rows.Cells.Value + "\n"
The above statement casts the object returned from the cell to a string. So this might trigger an error. For example if the cell's content is a number or an image, then you get an exception.
as for val = val + dataGridView1.Rows.Cells.Value.ToString() + "\n"
If the cell contains a number, it will be converted to a string, and no exception will happen. I am not sure if it was an image it will be converted to a string. In a nutshell this technique prevents some of the exceptions that might happen in the first statement.