c#减去合并数据表中的重复项

时间:2016-01-15 07:21:02

标签: c# .net linq merge concat

代码:

// Datatable DB
DataTable CashBillingsArticles_DB = new DataTable();
var CashBillingsArticles_DB_Primary = CashBillingsArticles_DB.Columns.Add("article_id", typeof(Int32));
CashBillingsArticles_DB.Columns.Add("article_quantity", typeof(Double));
CashBillingsArticles_DB.Columns.Add("article_sellprice", typeof(Double));
CashBillingsArticles_DB.Columns.Add("article_discount", typeof(Double));
CashBillingsArticles_DB.Columns.Add("article_isv", typeof(Double));
CashBillingsArticles_DB.Columns.Add("article_total", typeof(Double));
CashBillingsArticles_DB.PrimaryKey = new DataColumn[] { CashBillingsArticles_DB_Primary };

// DB Data
CashBillingsArticles_DB.Rows.Add(1, 1, 5, 0, 0, 5);
CashBillingsArticles_DB.Rows.Add(2, 2, 6, 0, 0, 12);
CashBillingsArticles_DB.Rows.Add(4, 1, 10, 0, 0, 10);
CashBillingsArticles_DB.Rows.Add(7, 2, 3, 0, 0.9, 6.9);

// DataTable Grid
DataTable CashBillingsArticles_Grid = new DataTable();
var CashBillingsArticles_Primary = CashBillingsArticles_Grid.Columns.Add("article_id", typeof(Int32));
CashBillingsArticles_Grid.Columns.Add("article_quantity", typeof(Double));
CashBillingsArticles_Grid.Columns.Add("article_sellprice", typeof(Double));
CashBillingsArticles_Grid.Columns.Add("article_discount", typeof(Double));
CashBillingsArticles_Grid.Columns.Add("article_isv", typeof(Double));
CashBillingsArticles_Grid.Columns.Add("article_total", typeof(Double));
CashBillingsArticles_Grid.PrimaryKey = new DataColumn[] { CashBillingsArticles_Primary };

// Grid Data
CashBillingsArticles_Grid.Rows.Add(2, 1, 6, 0, 0, 6);
CashBillingsArticles_Grid.Rows.Add(3, 1, 1, 0, 0.15, 1.15);
CashBillingsArticles_Grid.Rows.Add(4, 3, 10, 0, 0, 30);
CashBillingsArticles_Grid.Rows.Add(7, 4, 3, 0, 1.8, 13.8);

我需要显示此结果,比较表格中的article_id列,并始终显示数据表CashBillingsArticles_Grid的article_sellprice值:

id qty price desc  isv   total
1  -1   5     0    0     -5
2  -1   6     0    0     -6
3   1   1     0    0.15   1.15
4   2  10     0    0      20
7   2   3     0    0.9    6.9 

图示: 在数据库中我有: enter image description here

用户对发票进行一些修改,最终结果如下: enter image description here

我需要了解数据库和用户网格修改之间的差异,如下所示:(我需要此输出)

enter image description here

0 个答案:

没有答案