"Unable to case object of type 'System.Decimal' to type 'System.String' occuring within a LINQ statement.
Posted on 2010-11-22
The following LINQ statement is generating the error.
IEnumerable<String> keyValue = ((IEnumerable<String>)
from DataRow rows in dtPrimary.Rows
where rows[currentGroup.Peek().ColumnName.ToString()].ToString() == node.ToString()
The exception is occuring in the select portion: select (String) rows[key].Take(1).ToArray() due to the fact that several of the columns in dtPrimary are of type System.Decimal. When I initially wrote the code I was only interested in the Strings, however. Is there away for me to handle this without doing IEnumerable<object>? It would be best for me just to have all the decimal (or ints) convert to a string so that client code doesn't have to change.