views:

172

answers:

1

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.

+2  A: 

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
he's right without linked servers you are forced to work with them in memory... AsEnumerable() forces the queries (2) to execute.
J.13.L