Results 1 to 5 of 5

Thread: How do I use Multiple Joins and Conditions using LINQ?

Threaded View

  1. #1

    Thread Starter
    Lively Member Christhemist's Avatar
    Join Date
    Sep 2016
    Location
    Nevada
    Posts
    116

    How do I use Multiple Joins and Conditions using LINQ?

    I have three DataTables and Three conditions in which I need to combine into one "Combined" DataTable:

    Input:

    AddressList
    First
    Last
    Address
    City
    State
    Zip
    Offercode

    Matrix1
    Code
    Offer1

    Matrix2
    Code2
    Offer2

    Output: (CombinedDataTable)
    First
    Last
    Address
    City
    State
    Zip
    Offercode
    Offer1
    Offer2

    My syntax for the these are not working in the "On" and "Concat" portions:

    Code:
    Dim both = From row1 In AddressListDatatable.AsEnumerable()
                           Join row2 In Matrix1Datatable.AsEnumerable()
                           Join row3 In Matrix2Datatable.AsEnumerable()
                       On row1.Field(Of String)("Offercode") Equals row2.Field(Of String)("Code") And
                       On row1.Field(Of String)("Offercode") Equals row3.Field(Of String)("Code2")
                           Select addressListColumnNames.Select(Function(alcn) row1(alcn)).Concat(matrixColumnNames.Select(Function(mcn) 
                           row2(mcn)))  row1(alcn)).Concat(matrix2ColumnNames.Select(Function(mcn2) row3(mcn2)))
    
    For Each result In both
                    CombinedDataTable.Rows.Add(result.ToArray())
                Next
    Last edited by Christhemist; May 11th, 2018 at 11:19 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width