开发者

Convert DataTable to Linq

开发者 https://www.devze.com 2022-12-19 15:49 出处:网络
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\"))

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消