• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

Query results to data table

I need to build a table with the results of different LINQ queries.  I was trying to do this with a data table but now sure of the syntax.  An example of what I'm trying to do is below.
After I add all the columns and create all the other LINQ queries, How do I add/update the data table with the results? Or is there a better way then using a data table? Was I build the table and create calculate columns the end results will end up in an excel spreadsheet.
Using VB 2008  framework 3.5.

Dim ResultsTable as DataTable
Dim dc As New dcDSSDataContext
Dim TMADODList = From TMA In dc.vwCurrentTMA _
     Select TMA.DOD
Dim InterChgDODList = From IC In dc.datInterchangeableDOD _
      Select IC.DOD
Dim DODList = TMADODList.Union(InterChgDODList )
DODList = DODList.Distinct
ResultsTable = New DataTable("Results")
ResultsTable.Columns.Add("DOD", GetType(String))
ResultsTable.Columns.Add("Location", GetType(String))
'Other columns added here

Open in new window

  • 2
1 Solution
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
Think below will guide you in right way:

Creating a DataTable From a Query (LINQ to DataSet) ( http://msdn.microsoft.com/en-us/library/bb386921.aspx  )
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
MadIceAuthor Commented:
I get CopyToDataTable() is not a member of System.Liq.IQueryable(Of String) error. Do I need to add a reference?
I got the datatable to add new rows with the following
For Each DOD in DODList
    ResultsTable.Rows.Add(New Object() {DOD})

But how do I update Columns with the results of a different LINQ query?  I want to update the second Query?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now