+6 votes
212 views
in Software Testing by (1.3k points)

I have two tables table1 and table2 and i want to merge these table for a column with no duplicates value

Now if I use table1.Merge() I get the rows with both default and actual values for tag abc. I need only the actual values for a particular tag present in 2nd table, if not the default values from 1st table. How do i do this?

closed

1 Answer

+1 vote
by (1.2k points)
selected by
 
Best answer

you can use this 

var dt1 = new DataTable();
var prime1 = dt1.Columns.Add("Tag", typeof(string));
dt1.Columns.Add("Value", typeof(string));
dt1.Rows.Add(new object[]{"abc", "default"});
dt1.Rows.Add(new object[]{"xyz", "default"});
dt1.PrimaryKey = new DataColumn[]{ prime1 };

var dt2 = new DataTable();
var prime2 = dt2.Columns.Add("Tag", typeof(string));
dt2.Columns.Add("Value", typeof(string));
dt2.Rows.Add(new object[]{"abc", "12"});
dt2.PrimaryKey = new DataColumn[]{ prime2 };

dt1.Merge(dt2);

Result will come with saparate tag and value.

by (1.3k points)
Nice thanks!

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated