-2

2行を比較しようとすると、次のようなエラーが表示されます。

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.

私のコードは次のとおりです。

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()))

ToDoubleをToInt32に変更しようとしましたが、機能しません。

誰か教えてもらえますか、このエラーメッセージはどういう意味ですか?

どうもありがとう!!!

4

1 に答える 1

1

このエラーは、に変換できなかったことを意味しますdouble。デバッガーを接続し、変換しようとしている値を調べて、それが有効な数値ではない理由を確認します。

TryParse値を変換できないときに例外がスローされないようにメソッドを使用することも検討できます。

于 2012-08-27T15:28:16.420 に答える