2012-04-14 3 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.Value, String.Empty, 부동 소수점 값 또는 뭔가 다른 일 수 있습니다 - 대신 필드 이름을 사용한다 서수를 사용하는 방법으로

Convert.ToInt32(objReader.Item(4)) 

- 이렇게하면 올바른 필드를 사용하고 있는지 확인할 수 있습니다. 당신은 필드 이름을 알고있는 경우

, 그것을 사용 :이 데이터베이스에서 나오는 값이 정수로 convertable 있다고 가정

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

@Downvoter - 관심있는 관심을 가져주세요? – Oded

관련 문제