0
DataTable mdt = dt.AsEnumerable().GroupBy(r = >new {
    Col1 = r.Field < string > ("Parent Part Number"),
    Col2 = r.Field < string > ("Child#1 Part Number")
}).Select(g = >g.OrderBy(r = >r.Field < string > ("Parent Part Number")).First()).CopyToDataTable();

foreach(var data in mdt.AsEnumerable()) {

    Response.Write("value is " + data.Field < string > ("Parent Part Number") + " " + data.Field < string > ("Child#1 Part Number"));

}

Table like (Gridview sourced from a datatable) :

I am starting with linq and wondering if anybody knows how to add a select to the index of the rows picked after the condition of doing the groupby method from the code above.... this gives as outcome :

parent partnumber: GEC1H-PCB-00081-01 child partnumber: GEC1J-SW3555L11
parent partnumber: GEC1H-PCB-00091-01 child partnumber: GEC1J-SW3555L12
parent partnumber: GEC1H-PCB-00091-01 child partnumber: GEC1J-SW3555L11

and what I am looking is to identify the rows for which childpartnumber have a parentnumber column and that parent number be the first and omit the repeated ones like the rows of the following image:

Desired returned rows:

Any help will be most appreciated, Thanks

Matheus Cuba
  • 2,068
  • 1
  • 20
  • 31
Antonio
  • 87
  • 8
  • 1
    Maybe you should include a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) to explain what you want more clearly. Shorter numbers will do. – Gert Arnold Oct 14 '16 at 20:18
  • I am not following what you are trying to do when you are grouping by the anonymous type, but it seems like you are losing the reference to the DataRow when you do that... Maybe you can rewrite this so that you are selecting the entire DataRow instead - then it would still have all of its metadata intact. You could end up with a List and loop through that to accomplish something. Alternately, can you just leave your query alone but replace dt with the new DataTable that you are creating once it is complete? – Dave Smash Oct 14 '16 at 20:31
  • what I am looking for is to get the index of the desired returned rows image based on the linq query described – Antonio Oct 14 '16 at 20:34
  • @ElementalPete let me try to be as cleaner as I can, the goal of this is to validate that part numbers from parent and child columns exist by checking a store procedure in a DB. That is done by now and no there are no reasons for details, the thing now is that from the "Gridview sourced from a datatable" image, I need to filter and leave only the rows in which a childpartnumber has a different parentpartnumber as appeared on first time; meaning only rows 1, 6 and 8 will be picked. After that I will refresh the datatable as the "Desired returned rows" image attached . – Antonio Oct 14 '16 at 21:50
  • Why don't you include a simple sample program with simple data that demonstrates what you want and that answerers can copy and improve? These long numbers don't help and using images instead of text *certainly* doesn't help. – Gert Arnold Oct 15 '16 at 10:53

0 Answers0