如何解决此错误无法将类型为'System.Data.EnumerableRowCollection`1 [System.Data.DataRow]'的对象强制转换为'System.Data.EnumerableRowCollection`1 [System.Data.DataRow]'。 [英] how to solve this error Unable to cast object of type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' to type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]'.
问题描述
我使用的是Visual Studio 2013终极版,我有数据集并且它包含值。当我尝试单独获取RegID列值时,我得到了低于错误.RegID列没有空值
无法将'System.Data.EnumerableRowCollection`1 [System.Data.DataRow]'类型的对象强制转换为'System.Data.EnumerableRowCollection' 1 [System.Data.DataRow]'。
我的代码是
string StrRegID = string .Join(;,(来自DataRow objRow in objSet.Tables [0] .AsEnumerable()select objRow.Field< long>(RegID)。ToString())。ToArray());
为什么你有.AsEnumerable()
?
来自docs:AsEnumerable< TSource>(IEnumerable< TSource>)方法除了从实现IEnumerable< T>的类型改变源的编译时类型之外没有其他效果。到IEnumerable< T>本身。
Hi ,
I am using Visual Studio 2013 ultimate, i have dataset and it contains values.when i try to get the RegID column value alone i get the below error .RegID column does not have null value
"Unable to cast object of type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' to type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]'."
My code is
string StrRegID = string.Join(";", (from DataRow objRow in objSet.Tables[0].AsEnumerable() select objRow.Field<long>("RegID").ToString()).ToArray());
Why do you have the.AsEnumerable()
?
From docs:The AsEnumerable<TSource>(IEnumerable<TSource>) method has no effect other than to change the compile-time type of source from a type that implements IEnumerable<T> to IEnumerable<T> itself.
这篇关于如何解决此错误无法将类型为'System.Data.EnumerableRowCollection`1 [System.Data.DataRow]'的对象强制转换为'System.Data.EnumerableRowCollection`1 [System.Data.DataRow]'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!