13 November 2016

Unable to cast object of type 'System.Int32' to type 'System.String'.

I attended a student brainstorming session this morning. One of the students asked a question to the group about the possible reason why this error appeared on the screen:

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.

Many newbies assumed that it's a casting error. They even offered him numerous solutions without first inspecting the program.

10 minutes later, they still couldn't figure out the solution to the error.

When I checked it, my first instinct was to read his codes and inspect his SQL query. Then I found that the error appeared simply because he forgot the comma (,) between the two columns in his SQL query!

My advice: Read codes when debugging (and minimize the talking).


No comments:

Post a Comment