LINQ - cant group by using linq
Asked By hq
22-Aug-10 08:01 AM
i am using vb.net and dataset have two table and relation , i query only on the first table but i cant use group by on any filed of the table it give Definition of method 'GroupBy' is not accessible in this context here is the code
Dim Groups = From n In dataSetTableAsEnumerable _
Group n By n.filedName Into Group _
Select Group
Peter Bromberg replied to hq
I haven't used VB.NET for years, but in C# this works perfectly with the Nortwind Employees table
var grps = from n in ds.Tables[0].AsEnumerable() group n by n["ReportsTo"] into grp select grp;
you get 3 System.Linq.IGrouping objects each containing DataRows indexed on the "ReportsTo" group index. |
I think your problem may be caused by using a reserved word "Group" as a variable.
Chris replied to hq
Add to the top of your code (before the class/namespace definitions):
Help with Select Case statement please I am trying to create a procedure witht he following code in it Select Case @var8 When 0 - - Detail; Then set @SELECT = @SELECT + ' . . .' set @GROUP2 = ' . . . ' When 1 - - Total; Then set @SELECT = @SELECT + ' . . .' set @GROUP2 = ' . . . ' When 2 - - Summary; Nothing Then set SELECT = @SELECT + ' . . .' set @GROUP2 = ' . . ' End but I am getting errors. How can I correct this? Thanks, Burak
SELECT id, group FROM test tWHERE NOT EXISTS( SELECT 1 FROM auxData SQL Server SELECT id, group FROM test t WHERE NOT EXISTS ( SELECT 1 FROM auxData WHERE id = t.id AND group = t.group ); - - Aaron Bertrand SQL Server MVP http: / / www.sqlblog.com / http: / / www.aspfaq.com / 5006 SQL
is there a shorter code that would do the same thing? Sub WorksheetJump() ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select ActiveSheet.Previous.Select
Hello: I am trying to run the following kind of query using SQL Server 2005: SELECT ( SELECT (SELECT '1' AS '@id' FOR XML PATH('elem'), TYPE) FOR XML PATH('global'), TYPE ) FOR XML You can reduce that to a single FOR XML expression, using a path in the select clause alias and using the ROOT directive. Best regards Michael Mike, you may want to asp Your specific query below can be rewritten as one FOR XML PATH query as SELECT '1' AS 'elem / @id' FOR XML PATH('global'), ROOT Best regards Michael. keywords: Xquery, xml Hello: I am trying to run the following kind of query using SQL Server 2005: SELECT ( SELECT (SELECT '1' AS '@id' FOR XML PATH('el
select from (select union select) hi, I am trying to do something like this select * from (select . . . from . . . where . . . UNION select . . . from . . . where. . .) but I get the message : Incorrect syntax near ')'. why cant I do that thanks alot. . . You have to provide a table alias to your sub-query: select * from (select . . . from . . . where . . . UNION select . . . from . . . where. . .) A SQL Server Helper http: / / www.sql-server-helper