Using Linq on a Dataset

Posted by JasonMHirst on Stack Overflow See other posts from Stack Overflow or by JasonMHirst
Published on 2010-05-18T11:27:10Z Indexed on 2010/05/18 11:30 UTC
Read the original article Hit count: 212

Filed under:
|
|

Can someone enlighthen me with regards to Linq please?

I have a dataset that is populated via a SQL Stored Procedure, the format of which is below:

Country | Brand | Variant | 2004 | 2005 | 2006 | 2007 | 2008

The number of rows varies between 50 and several thousand.

What I'm trying to do is use Linq to interrogate the dataset (there will be several Linq queries based on user options), but a simple example would be to SUM the year columns based on Brand.

I have the following that I believe creates a template for me to work with:

But from here on I'm absolutely stuck!

                sqlDA.Fill(ds, "Profiler")

            Dim brandsQuery = From cust In ds.Tables(0).AsEnumerable()
                              Select _BrandName = cust.Item("BrandName"),
                              _y0 = cust.Item("1999"),
                              _y1 = cust.Item("2004"),
                              _y2 = cust.Item("2005"),
                              _y3 = cust.Item("2006"),
                              _y4 = cust.Item("2007"),
                              _y5 = cust.Item("2008")

I'm tried to look at examples, but can't see any that are VB.Net based and/or show me how to Sum/Group.

Can someone please provide an example so I can perhaps learn from it.

Thanks.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about LINQ