如何解决此错误无法将类型为'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]'.

查看:806
本文介绍了如何解决此错误无法将类型为'System.Data.EnumerableRowCollection`1 [System.Data.DataRow]'的对象强制转换为'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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆