2

How do you join two data tables from different source databases in .NET? Ideally, I can craft two queries manually and simply join on a single field.

In this case, linked servers and scheduled imports are not an option. I've looked into the data relation object, but (correct me if I'm wrong) that only works for parent-child relationships.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

3

I had a similar situation where I had 2 datatables and joined them using LINQ.

Here is the code from my situation, maybe it'll help you out.

  var combinedRows = 
         from t in dt_t.AsEnumerable()
         join sap in dt_sap.AsEnumerable() on t.Field<System.Int32>("line_no").ToString() equals sap.Field<System.String>("PO_Item")                           
         orderby t["line_no"]
         select new { t, sap };
MDStephens
  • 1,013
  • 2
  • 9
  • 10
  • he's right without linked servers you are forced to work with them in memory... AsEnumerable() forces the queries (2) to execute. – bytebender Jun 15 '09 at 19:37