Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Jumpstart in linq
Message
 
À
19/09/2011 17:45:40
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01523960
Message ID:
01523973
Vues:
52
>>>select field1, sum(field2) as total from mytable group by field1
>
>Is mytable a datatable?
>Is it in a typed.dataset?

a datatable, extracted via a query on an access database (that's what oSql does, it fills osql.dt from the qryBestelKK)
        Dim osql As New sqlClass : osql.Execute("qryBestelKK")
        Dim orders As IEnumerable(Of DataRow) = osql.dt.AsEnumerable

        Dim test = From r In orders _
                   Group r By name = r.Field(Of String)("KL_Naam") _
                   Into g = Group Select New With {.Name = name, .total = g.Sum(Function(r) r.Field(Of Decimal)("Bestd_Waarde"))}

        For Each r In test
            Console.WriteLine("name: {0} total {1}", r.Name, r.total)
        Next
essentially copied it from
' Fill the DataSet.
Dim ds As New DataSet()
ds.Locale = CultureInfo.InvariantCulture
' See the FillDataSet method in the Loading Data Into a DataSet topic.
FillDataSet(ds)

Dim products As IEnumerable(Of DataRow) = _
    ds.Tables("Product").AsEnumerable()

Dim query = _
    From product In products _
    Group product By style = product.Field(Of String)("Style") Into g = Group _
    Select New With _
        { _
            .Style = style, _
            .AverageListPrice = g.Average(Function(product) _
                    product.Field(Of Decimal)("ListPrice")) _
        }

For Each product In query
    Console.WriteLine("Product style: {0} Average list price: {1}", _
        product.Style, product.AverageListPrice)
Next
Not sure I understand it, but it does work. :)

http://msdn.microsoft.com/en-us/library/bb386991.aspx

Thanks for caring and kind regards,

Marc

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform