Link to home
Start Free TrialLog in
Avatar of MadIce
MadIce

asked on

Update Datatable with the results of a LINQ query

Not sure how/or best way to do this. I have a datatable with part of the data needed (look at code). The code works. But now I want to run another LINQ query something like this

Dim TList = From TL In dc.vwTL
          Select TL.DOD, TL.Test

and now update my Datatable with the TL.Test info.  I actually have many other columns that will need to update the datatable the same way to include calculations.  Using VB 2008 framework 3.5.  had a simular question. Thanks in advance
Dim TMDODList = From TM In dc.vwCurrent_datTMs _
                        Select TM.DOD
 
            ResultsTable = New DataTable("Results")
 
              'Create the cols for the table
            ResultsTable.Columns.Add("DOD", GetType(String))
            ResultsTable.Columns.Add("Test", GetType(Integer))
 
            For Each DOD In TMDODList
                ResultsTable.Rows.Add(New Object() {DOD})
            Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MadIce
MadIce

ASKER

CodeCruiser,
It looks like your example will work but I get an error on the the second line (for the Rowfilter).
The error is "Cannot find Column(A1).
A1 is the value for the first DOD. I need to filter on DOD not Test. It seem like that should work. Any Ideas
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MadIce

ASKER

I had to adjust code for nullable value but answer is just what I was looking for.
If T.Test.HasValue Then ResultsTable.DefaultView.Item(0).Item("Test") = T.test
Thanks alot. Was getting ready to go back to using Store Procedure