I suspect your code doesn't look like that - Visual studio would have tidied up the indentation for you - so it will really depend on what your real, executing code looks like: I don't think you have the
dt.Rows.Count>0
test in the "live" code, as the only way it should get to the row access is if there
is a row at position 0.
So start by checking you code, and if you think it's all correct, use VS to auto tidy the indentation using CTRL+K CTRL+D - if it compiles ok then it will work - and show us that code,
or use the debugger to examine the DataTable immediately prior to the
if
test.