c# - Avoid repeating columns in DataTable? -
this datatable:
itempartnumber vendorname price annf213 samsung 265.41 gdff31d hp 65.10 annf213 apple 115.51 fsf2122 microsoft 655.47 gdsgg32 nokia 250.58 annf213 samsung 225.40 it has annf213 3 times. want take first one, , wish omit rest rows.
desired output datatable:
itempartnumber vendorname price annf213 samsung 265.41 gdff31d hp 65.10 fsf2122 microsoft 655.47 gdsgg32 nokia 250.58 so, simple question how rows after omitting repeating particular column values?
i've tried:
dataview view = new dataview(datatable); datatable = view.totable(true, "itempartnumber", "vendorname", "price"); //this isn't working. datatable = view.totable(true, "itempartnumber"); //this working, `itempartnumber` there on data table, need 3 columns. me in this!
i use linq-to-datatable, if want keep first:
datatable = datatable.asenumerable() .groupby(row => row.field<string>("itempartnumber")) .select(grp => grp.first()) .copytodatatable(); if want more meaningful, example keep row highest price:
datatable = datatable.asenumerable() .groupby(row => row.field<string>("itempartnumber")) .select(grp => grp.orderbydescending(row => row.field<decimal>("price")).first()) .copytodatatable();
Comments
Post a Comment