2012-04-14 23 views
0

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 30: lbl_userName.Text = objReader.Item(0) & " " & objReader.Item(1)
Line 31: lbl_resumeHead.Text = objReader.Item(3)
Line 32: lbl_experience.Text = Convert.ToInt32(objReader.Item(4))

テーブルからIntegerの値を表示する方法。

答えて

2
Convert.ToInt32(objReader.Item(4)) 

これは、データベースからの値が整数に変換可能であることを前提としています。パースされない文字列の場合は、DbNullなどが失敗します。

documentationの例がさらにあります。

5

あなたobjReader.Item(4)有効な整数値が含まれていません - それはDBNull.ValueString.Empty、浮動小数点値または何か他のことがあります - 代わりに、あなたはフィールド名を使用する必要があり序を使用するところで

Convert.ToInt32(objReader.Item(4)) 

- 正しいフィールドを使用していることを確認してください。

あなたはフィールド名を知っている場合は、それを使用する:

Convert.ToInt32(objReader("MyIntegerField")) 
+3

@Downvoter - コメントしますか? – Oded

関連する問題