C# compare two Lists and update it's column values -
i've got 2 c# lists (list lista , list listb) how can compare these 2 , if duplicate (of specific columns ex. id_num , id_cust) found update column "id_duplicate" value of listb's columns id.
dataset ds = submain; list<string> lista = (from r in ds.tables[0].asenumerable() select r.field<string>("id_num") + r.field<string>("id_cust")).tolist(); dataset dsmain = mains; list<string> listb = (from r in dsmain.tables[0].asenumerable() select r.field<string>("id_num") + r.field<string>("id_cust")).tolist();
i want lista
contain new column id_duplicate
value id_num
listb
.
so duplicates somehow linked id_num
.
i update id_duplicate
database.
edit: added more explanation in comment bellow.
if understand join:
var lista = new list<row> { new row { id= 1, idnum = 1, idcust = 1 }, new row { id= 2, idnum = 1, idcust = 2 }, new row { id= 3, idnum = 2, idcust = 1 }, new row { id= 4, idnum = 1, idcust = 3 }, new row { id= 5, idnum = 3, idcust = 1 }, new row { id= 6, idnum = 4, idcust = 1 } }; var listb = new list<row> { new row { id= 1, idnum = 5, idcust = 1 }, new row { id= 5, idnum = 6, idcust = 2 }, new row { id= 7, idnum = 2, idcust = 1 }, new row { id= 9, idnum = 1, idcust = 3 }, new row { id= 11, idnum = 7, idcust = 2 } }; var t = (from in lista join b in listb on a.idcust.tostring() + a.idnum.tostring() equals b.idcust.tostring() + b.idnum.tostring() select new { id = a.id, idupdate = b.id }).toarray(); foreach (var item in t) { console.writeline("id {0} idupdate {1}", item.id, item.idupdate); }
here row class
class row { public int id { get; set; } public int idnum { get; set; } public int idcust { get; set; } }
obviusly can create calculated column on row class this
public string valuetocompare { { return this.idnum.tostring() + this.idcust.tostring(); } }
and use on join comparison
max
Comments
Post a Comment