0
我有两个数据表中,首先包含如何根据条件合并两个包含不同列的数据表?
DataTable dtMaterialStatement = new DataTable();
dtMaterialStatement.Columns.Add(new DataColumn("MaterialNo", Type.GetType("System.String")));
dtMaterialStatement.Columns.Add(new DataColumn("MaterialId", Type.GetType("System.String")));
dtMaterialStatement.Columns.Add(new DataColumn("Qty", Type.GetType("System.Double")));
dtMaterialStatement.Columns.Add(new DataColumn("Unit", Type.GetType("System.String")));
dtMaterialStatement.Columns.Add(new DataColumn("SinglePrice", Type.GetType("System.Decimal")));
dtMaterialStatement.Columns.Add(new DataColumn("PricePerPack", Type.GetType("System.Decimal")));
dtMaterialStatement.Columns.Add(new DataColumn("UnitsPerPack", Type.GetType("System.String")));
dtMaterialStatement.Columns.Add(new DataColumn("Discount1", Type.GetType("System.Decimal")));
dtMaterialStatement.Columns.Add(new DataColumn("Discount2", Type.GetType("System.Decimal")));
dtMaterialStatement.Columns.Add(new DataColumn("Discount3", Type.GetType("System.Decimal")));
dtMaterialStatement.Columns.Add(new DataColumn("SalesPrice", Type.GetType("System.Decimal")));
dtMaterialStatement.Columns.Add(new DataColumn("Exist", Type.GetType("System.Boolean")));
二包含: -
"MaterialNo"
Qty
"Unit"
"SinglePrice"
"PricePerPack"
"UnitsPerPack"
"Discount1"
"Discount2"
"Discount3"
"SalesPrice"
,并配备额外的列,
我想合并这两个表中,如果第一TABEL的MaterialNo是相同的用第二个表的MaterialNo列,然后从第二个表中取出公共列字段值来更新第一个值对应列的值。 else在第一个表中插入一个新行,使用表的第一列,但是从第二个表中取值。