我有2个数据表:
_wizardStepSelectUnitDataSet.WizardStepSelectUnits_UnitsSelectedInOtherAgreements
和
_wizardStepSelectUnitDataSet.WizardStepSelectUnits_SelectedUnits
模式是相同的,我需要知道两个数据表中存在哪些行,
如何将其转换为新的数据表?
没有CODE: 我只设计了2个数据表。它们已经在内存中填充了一些数据。
我需要知道使用一个ID字段的两个数据表之间的公共行。
我无法复制设计师的代码,你将不堪重负。
我试过这个: var result = 从r in _wizardStepSelectUnitDataSet.WizardStepSelectUnits_UnitsSelectedInOtherAgreements.AsEnumerable() 在_wizardStepSelectUnitDataSet.WizardStepSelectUnits_SelectedUnits.AsEnumerable()中加入c 在r.Field(“UnitId”)等于c.Field(“UnitId”) 选择r;
DataRow[] dr = result.Select(
String.Format(CultureInfo.InvariantCulture.DateTimeFormat,"StartDate <= #{0}#", stopDate));
但是我遇到了编译器错误: 错误7无法从用法推断出方法'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable,System.Func)'的类型参数。尝试显式指定类型参数。 C:\ BITProjects \ TeamSystem \ luival \ refm \ DEV \ AgreementModule \ GUI \ WorkItems \ UC021_HuurovereenkomstWizard_WorkItem.cs 511 28 Ceusters.REFM.AgreementModule.GUI
谢谢
答案 0 :(得分:0)
确定表格中的unique_id字段,然后
SELECT * FROM table1,table2 表格1.unique_id = table2.unique_id
如果您对返回的内容感到满意,可以根据select。
构建插入语句答案 1 :(得分:0)
我对LINQ不太好,但也许你想尝试这种方法?
var result = from r in dt.AsEnumerable()
join c in dt2.AsEnumerable()
on r.Field<string>("col1") equals c.Field<string>("col1")
select r;
然后是两个表中的所有列。
我确信有比较完整行而不是字段/列的方法。
答案 2 :(得分:-1)
使用System.Data.DataTable.Merge(),请参阅:http://msdn.microsoft.com/en-us/library/fk68ew7b.aspx
编辑:可能不是一个相关的答案,我误读“两个表都存在”。是的,你正在寻找的是其他人推测的交叉点。