I have two datatable , first contain
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")));
Second contain:-
"MaterialNo"
Qty
"Unit"
"SinglePrice"
"PricePerPack"
"UnitsPerPack"
"Discount1"
"Discount2"
"Discount3"
"SalesPrice"
and come extra column ,
I want to merge both table , if MaterialNo of first tabel is same with second table MaterialNo column , then take common column field value from second table to update value of first value corresponding columns.
else insert a new row in first table with using column of table first but taking value from second table.
Use this one to extract a new datatables that only contains differences http://kodesharp.blogspot.com/2007/12/c-compare-2-datatables-and-return-3rd.html
Then use
foreachorforloop to manually extract the differenes into array. Then have it repumped into the datatableSomething like this: