1 Replies - 181 Views - Last Post: 28 November 2017 - 08:04 AM Rate Topic: -----

#1 t3cho  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 227
  • Joined: 27-May 14

Filter datatable and select

Posted 28 November 2017 - 07:57 AM

First of all i need to group and list "Base" and for each of those values i need to write in console.

  Dim dt As New DataTable
        dt.Columns.Add("Base")
        dt.Columns.Add("ID")
        dt.Columns.Add("Description")

        dt.Rows.Add("1", "11", "A")
        dt.Rows.Add("1", "12", "A")
        dt.Rows.Add("2", "13", "A")
        dt.Rows.Add("2", "14", "A")
        dt.Rows.Add("1", "15", "A")
        dt.Rows.Add("1", "16", "A")

        Dim query = From row In dt
                    Group row By Base = row.Field(Of String)("Base") Into BaseGroup = Group
                    Select New With {
            Key Base,
            .Base = BaseGroup.Sum(Function(r) r.Field(Of String)("Base"))}

        For Each x As Object In query
            ' SWITCH TO NEW EXCEL SHEET
            Dim dtTemp As DataTable = dt

            Dim foundRows() As DataRow
            foundRows = dtTemp.Select("Base=" & x.Base)

            For i As Integer = 0 To foundRows.GetUpperBound(0)
                ' WRITE VALUES IN EXCEL SHEET
                Console.WriteLine("For base"  & x.base & "found values" & foundRows(i)(1))
            Next i

        Next


This is my first usage of LINQ :)/> I think my main problem is here but i cant figure out
.Base = BaseGroup.Sum(Function(r) r.Field(Of String)("Base"))}

/>

This post has been edited by t3cho: 28 November 2017 - 08:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Filter datatable and select

#2 maceysoftware  Icon User is offline

  • Foo
  • member icon

Reputation: 353
  • View blog
  • Posts: 1,530
  • Joined: 07-September 13

Re: Filter datatable and select

Posted 28 November 2017 - 08:04 AM

Whats your issue?

I mean I could stick your code in a project and test it, but why don't you tell me what your seeing and/or why you think its wrong?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1