Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Linq query adding results to a new table

Linq query adding results to a new table

Scheduled Pinned Locked Moved ASP.NET
databasecsharplinqxmlquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    I am using Linq query to pull the latest 3 dates for a given record: EEGRP, EID. However I am having issues when adding a new row into new table with non key columns:

    result.Rows.Add .... item.EENAML.. etc.

    Could you tell me what I am doing incorrect?

    Dim data = myDataTable.AsEnumerable().GroupBy(Function(r) New With {Key .EEGRP = r.Field(Of String)("EEGRP"), Key .EESSN = r.Field(Of String)("EID")},
    Function(key, rows) New With
    {
    Key .EEGRP = key.EEGRP,
    Key .ESSN = key.EID,
    .Dates = rows.Select(Function(r) r.Field(Of DateTime?)("DEIBCY") & ("DIIBYR") & ("D.DIIBMT") & ("DEIBDY")) _
    .OrderByDescending(Function(d) d).Take(3).ToList()
    })

                        'Create new table with original table schema
                        Dim result As New DataTable
                        result = myDataTable.Clone()
                       'Create new  row
                        For Each item In data
                            result.Rows.Add(item.EEGRP,item.EID, item.EENAML,item.EENAMF,item.EENAMM,item.EEADD1,item.EEADD2,,,, \_
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups