I've got three DataTables that I need to join together, and use the joined data as the DataSource for a GridView. The first (localSQLTable
) is populated via a query against an MS-SQL database. The second two (serviceResponse.Tables(0)
and serviceResponse.Tables(1)
) are built using DataSet.ReadXML
from the results of a web service.
I've gotten this far:
Dim joinedData = From f In localSQLTable _
Join s1 As DataRow In serviceResponse.Tables(0) _
On f.Item("KNum") Equals s1.Item("Number") _
Join s2 As DataRow In serviceResponse.Tables(1) _
On s1.Item("KNumber_Id") Equals s2.Item("KNumber_Id") _
Select Guid = f.Item("Guid"), Num = f.Item("Num"), Desc = f.Item("Desc"), KNum = f.Item("KNum"), KDesc = s2.Item("KDescription_Text"), Type = s2.Item("Type") _
Where (Type.ToString.ToUpper = "LONG_HTML")
myGridView.DataSource = joinedData
myGridView.DataBind()
However, it seemed joinedData
is just an IEnumerable (of anonymous type). I've tried a few things, including the following:
- Attempting to build
joinedData
as an IEnumerable(Of DataRow) using a lambda function (of which I am not familiar at all) to build the new DataRow - Calling
.ToList()
or.AsEnumerable()
(after toying with types) on the result set
The main issue is that no matter what I seem to try, there's something wrong with using the results as the DataSource for my GridView - I got one of the two exceptions:
- The data source for GridView with id did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
- The data source does not support server-side data paging.
I also know I probably shouldn't be using .Item ("Field")
instead of the strongly-typed .Field (Of T)("Field")
in my Linq query - I was waiting on that change until I've got the data actually usable.
I'm not married to Linq; if DataSet.Merge
is more appropriate (or some other methodology), I'll entertain it. There's also a distinct possibility that I'll actually have to join what I have to another two DataTables later. If that's the case, I'll likely merge the serviceResponse
tables into one, so I'll still only be joining three tables.
So what can I do to join this data together and use the result as my GridView's DataSource? And is anything I'm doing going to be any faster than just tacking on two extra columns in my original DataTable (localSQLTable
) and filling them row-by-row using the XML response data?