Click here to Skip to main content
15,851,711 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
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());
ZurdoDev 2-Jul-14 9:59am    
Looks like you're trying to do too much in one line. Break it out so that it makes more sense and then you'll see where the error is.
member33 2-Jul-14 16:54pm    
try this

tring.Join(";", (from DataRow objRow in objSet.Tables[0].AsEnumerable() select objRow.Field("RegID").ToString()).ToList().ToArray());
Matt T Heffron 2-Jul-14 19:34pm    
Adding the .ToList() before the .ToArray() is nonsense.
Both take an IEnumerable<T> and build the corresponding collection.

1 solution

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. 
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900