从.NET中的不同源数据库加入两个数据表?

时间:2022-05-20 08:29:01

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.

如何从.NET中的不同源数据库连接两个数据表?理想情况下,我可以手动制作两个查询,只需加入一个字段即可。

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 个解决方案

#1


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

我有类似的情况,我有2个数据表,并使用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 };

#1


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

我有类似的情况,我有2个数据表,并使用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 };