Linq query adding results to a new table
ASP.NET
1
Posts
1
Posters
0
Views
1
Watching
-
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,,,, \_