We need to do some basic breaking down of the problem: Declare a temporary variable
var foo = from myRow in dtInventory.AsEnumerable() select myRow;
Put on a breakpoint on the above and execute, if foo has rows then you've a different problem so move on. Relying on the table having data is no good. Though I doubt this is your problem, you just get a null or empty value in
result
Step 2 is to replace
letters[0].ToString()
with *any* letter, e.g.
"a"
(as per Kuthuparakkal suggestion). If you don't get the exception, your array is null at the very least.
If you do get an exception then the problem is
myRow.Field<string>("Description")
is returning null. You've then got two immediate culprits to investigate: either your field name doesn't match (case sensitive?) or the field itself allows null (loop over the unfiltered results and get each value in turn to see).
If all this fails to diagnose your problem, the only other thing that leaps out is the
dtInventory.AsEnumerable()
, if this causes
myRow
to lose the it's column information/context, the
.Field<t></t>
won't work. This is
very unlikely (I've not used this method) given that your code builds, but you could try re-removing the
where
clause and looping through the unfiltered results, inspecting each
DataRow
object in turn.