Results 1 to 2 of 2

Thread: [RESOLVED] Linq DataTable

  1. #1

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Resolved [RESOLVED] Linq DataTable

    Hello

    Need a quick help, with a query...

    I need to get a list of distinct names inside the data table and the sum of values for each one.
    I know some basic stuff about linq, but i don't know how to put the distinct and the sums together.

    The SQL Query:
    SQL Code:
    1. SELECT DISTINCT username,
    2.                 [Sum1] = SUM(day1),
    3.                 [Sum2] = SUM(day2)
    4. FROM dbo.History
    5. WHERE username LIKE '%something%'
    6. GROUP BY username

    How can i do this query in linq?

    Thanks

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  2. #2

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Linq DataTable

    Solved.

    vb.net Code:
    1. Dim query = From reg In _dt.AsEnumerable
    2. Group reg By username= registo.Field(Of String)("username") Into gpUsers = Group
    3.         Select New With {
    4.                    .UserName= username,
    5.                    .Day1= gpUsers.Sum(Function(reg) reg.Field(Of Decimal)("day1")),
    6.                    .Day2= gpUsers.Sum(Function(reg) reg.Field(Of Decimal)("day2")),
    7.           }

    Rate People That Helped You
    Mark Thread Resolved When Resolved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width