开发者

Datatable Grouping Using Linq and VB .NET

I'm completely dense here, but I'm trying to get some stats from a DataTable. One of the columns in the datatable is called "colour".

I need to find out how many of each instance of "colour" are in the datatable.

I'm trying:

Dim q = From p In PGWorkingDataTable _
            Group p By p("colour") Into Group _
            Select Group

But I get the compiler error at design-time: "Range variable name can be inferred only from a simple 开发者_高级运维or qualified name with no arguments" on the p("colour") section.

I need some serious guidance here. Thanks for your help.

Joe


You need to specify a name for the group key:

From p In new DataTable() _
Group p By Color = p("colour") Into Group _
Select Group


Writing LINQ in VB.NET is nobody's favorite thing. Try something like the following:

Dim q = From p In PGWorkingDataTable _
        Group By colour = p("colour") _
        Into colourCount = Count(p("colour")) _
        Select colour, colourCount
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜