Convert DataTable to Linq
I'm trying to convert DataTable to Linq using
DIm result = From r in dt.AsEnumerable()
Select new ( col1 = r.Field<i开发者_运维百科nteger>("id"), col2 = r.Field<string>("desc"))
But i get error near 'new (' saying type expected.
What is wrong with this query?
http://msdn.microsoft.com/en-us/library/bb531249.aspx says to use the syntax
New With { ... }
I thought it was New { ... }
Edit: it is New With
in VB. Confusing my C# and VB again. I can't see why (as the comment to the accepted answer says), "result" wouldn't be declared. Without a code sample, it's hard to tell.
精彩评论