none
Joining 2 datasets and returning only specified results RRS feed

  • Question

  • Dim Testing = ds.Tables("Testing").AsEnumerable
    Dim Letters = ds.Tables("Letters").AsEnumerable
    
    Dim ltrsQry = From t In Testing, l In Letters _
    Where t!blocklettergroup1 = l!LetterGroup _
    Group t By Description = t.Field(Of String)("description") Into Group _
    Select Description, LastCapDate = Group.Max(Function(p) p("capturedon"))

    Ok so here is my problem, as a new person to VB 2010 and LINQ I'm not sure if this can be done so I figured I'd ask...  I'm joining together 2 DataSets (Letters and Testing) and getting the most recent date that is in 'capturedon', this works fine.  What I need to do is figure out how to also get some of the other columns from the dataset, to make it easy lets just say two  (lastprintedon and Lettergroup which is found in the letters dataset).  Or <blocklettergroup1 in Testing which corresponds to Lettergroup in Letters> and <lastprintedon from Letters>.

    If this doesn't make sense let me know and I'll try to explain it better.

    Thursday, July 8, 2010 3:16 PM

Answers

  • Dim ltrsQry = From t In Testing, l In Letters _
          Where t!blocklettergroup3.Equals(l!lettergroup) OrElse t!blocklettergroup2.Equals(l!lettergroup) _
    OrElse t!blocklettergroup1.Equals(l!LetterGroup) _ Group t By Description = t.Field(Of String)("description"), _ ltrGroup = l.Field(Of String)("LetterGroup"), lastprintedon = l.Field(Of Date)("lastprintedon") Into Group Select Description, ltrGroup, lastprintedon, capDatee = Group.Max(Function(p) p("capturedon"))
    That seems to have fixed the "problem"
    • Marked as answer by temlehdrol Thursday, July 8, 2010 5:38 PM
    Thursday, July 8, 2010 5:38 PM

All replies

  • Minor change... changed the group and capturedon to lastprinted on

    Dim ltrsQry = From t In Testing, l In Letters _
    Where t!blocklettergroup1 = l!LetterGroup _
    Group l By Description = t.Field(Of String)("description") Into Group _
    Select Description, LastPrintDate = Group.Max(Function(p) p("lastprintedon"))
    Thursday, July 8, 2010 4:46 PM
  • I think I may have it... want to try a few more things first
    Thursday, July 8, 2010 5:14 PM
  • Dim ltrsQry = From t In Testing, l In Letters _
          Where t!blocklettergroup3.Equals(l!lettergroup) OrElse t!blocklettergroup2.Equals(l!lettergroup) _
    OrElse t!blocklettergroup1.Equals(l!LetterGroup) _ Group t By Description = t.Field(Of String)("description"), _ ltrGroup = l.Field(Of String)("LetterGroup"), lastprintedon = l.Field(Of Date)("lastprintedon") Into Group Select Description, ltrGroup, lastprintedon, capDatee = Group.Max(Function(p) p("capturedon"))
    That seems to have fixed the "problem"
    • Marked as answer by temlehdrol Thursday, July 8, 2010 5:38 PM
    Thursday, July 8, 2010 5:38 PM