Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4339436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:12:58+00:00 2026-05-21T11:12:58+00:00

I’ve got three DataTables that I need to join together, and use the joined

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:12:59+00:00Added an answer on May 21, 2026 at 11:12 am

    The end result of all of this is the following:

    Dim joinedData As Generic.IEnumerable(Of DataRow) = (From f In localSQLTable.AsEnumerable() _
                                                         Join h In serviceResponse.Tables(0).AsEnumerable() _
                                                         On h.Item("serviceknum") Equals f.Item("knum") _
                                                         Select GetFinalDataRow(finalTable, f, h))
    
    gvGridOne.DataSource = joinedData.CopyToDataTable()
    gvGridOne.DataBind()
    

    I explicitly defined the DataTable and schema (by adding DataColumns) of the ending DataTable I need, then passed that DataTable and the two DataRows in my join to GetFinalDataRow(), defined as:

    Public Function GetFinalDataRow(ByRef FinalTable As DataTable, ByVal Row1 As DataRow, ByVal Row2 As DataRow) As DataRow
        Dim newRow As DataRow = FinalTable.NewRow()
        For Each col As DataColumn In FinalTable.Columns
            If Row1.Table.Columns.Contains(col.ColumnName) Then
                newRow(col.ColumnName) = Row1.Item(col.ColumnName)
            ElseIf Row2.Table.Columns.Contains(col.ColumnName) Then
                newRow(col.ColumnName) = Row2.Item(col.ColumnName)
            Else
                newRow(col.ColumnName) = ""
            End If
        Next
    
        Return newRow
    End Function
    

    My joinedData object is now an IEnumerable of DataRows, and I can copy that to a DataTable for my GridView’s datasource, and it will auto generate columns and allow paging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.