Join two data tables from different source databases in .NET?

强颜欢笑 提交于 2019-12-13 16:31:07

问题


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.


回答1:


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 };


来源:https://stackoverflow.com/questions/997847/join-two-data-tables-from-different-source-databases-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!