Exception information is not shown, but most likely the exception is in
dr[20]
. Or
dr[7]
. It looks like you have less columns in data reader output than you assume — just look at your query.
The code is generally bad.
Immediate constants like 2, 7, 20 make the code hard to support. Also, if you have more than 1 row, you keep assigning the reading to the same variable over and over, loosing the previously assigned values, so the whole block inside data reader reading block makes no sense: the result of it is assigning only the values from the same row. And you should not close connection every time to open it again and again on each call to
details
. It's much better opening the connection on demand and keep it open, using the
lazy evaluation strategy (
http://en.wikipedia.org/wiki/Lazy_evaluation[
^]).
—SA