Can someone explain to me, please?

I understand something but i want to understand fully!

Or any video or something that i can watch ???

Hi @170290064

Check this tutorial playlist:

Hey @170290064

.GroupBy(Function(g) New With {Key .Names = g(“Color”)}): This groups the DataRow objects based on the values in the “Color” column, here each group contains all the rows with the same color.

.OrderBy(Function(r) r.Key.Names.ToString()): This sorts the groups based on the “Color” column in ascending order.

.Select(Function(s) New With {.Names = s.Key.Names.ToString(), .Count = s.AsEnumerable().Count()}): This projects each group into a new object with two properties: “Names” and “Count”. “Names” will store the color name as a string, and “Count” will store the number of rows in each group (i.e., the number of occurrences of that color).

.ToList().ForEach(Sub(row) in_DtColorCount.Rows.Add(row.Names, row.Count)): This converts the result of the previous step into a List and then iterates through each element of the list. For each element (representing a color group), it adds a new row to a DataTable called in_DtColorCount. This new row contains two columns: “Names” (representing the color name) and “Count” (representing the number of occurrences of that color in the original DataTable).

1 Like

Hi @170290064 ,

You could check out videos which are already available on Youtube. Would recommend you to go through the Video playlist of the below Youtuber :

Also, some of the tutorials here already on Linq :

1 Like
  1. So in the above code, we parse through the DtOtomobil datatable and group the datatable based on the column Color in your table.

  2. The grouped result is ordered in ascending format based on color. Eg: - rows with color black first then rows with color blue etc.

  3. Next step is we choose the color value from each group and the count of how many rows are in that group. This result is then converted in a list format.

  4. Finally using a for each we parse through the list result and add each entry to the datatable dtColorCount

To understand what each method does you can go through : LINQ - Query Operators | Tutorialspoint

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.