【发布时间】:2016-08-26 07:24:54
【问题描述】:
我对 C# LINQ 查询有点困惑。我有一个表,其值如下所示
DataTable tableold = new DataTable();
tableold.Columns.Add("Dosage", typeof(int));
tableold.Columns.Add("Drug", typeof(string));
tableold.Columns.Add("Patient", typeof(string));
tableold.Columns.Add("Date", typeof(DateTime));
// Here we add five DataRows.
tableold.Rows.Add(25, "Indocin", "David", DateTime.Now);
tableold.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
tableold.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
tableold.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
tableold.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
现在我有另一张桌子
DataTable tableNew = new DataTable();
tableNew.Columns.Add("Dosage", typeof(int));
// Here we add five DataRows.
tableNew.Rows.Add(25);
tableNew.Rows.Add(50);
tableNew.Rows.Add(10);
我需要将值保留在 tableold(基表)中,而这些值在 tableNew(新表)中不存在。
所以我需要更新的数据表(tableold)看起来像这样:
21, "Combivent", "Janet", "10:20:00"
100, "Dilantin", "Melanie", "10:20:00"
如何在 c# 或 LinQ 中编写这样的查询
请帮忙!谢谢
【问题讨论】:
-
我不知道如何在代码中添加 3 行 = 5 行,以及您如何期望 2 行输出。但是,您实际尝试了什么?我猜你想从最新表中选择 tiesm,并使用你选择的“数字”从旧表中选择相应的行..
-
我想不存在加入并删除两个表中相同的行,我需要一个最终更新的表
-
嗯,听起来你还没有尝试过.. 显示你尝试了什么以及它是如何不起作用的