How to combine or group table data by a specifik column

I have a datatable with those value

CenterID,CourseName,Price
1234, C#1, 1000
1234, C#2, 2000
3572, Python, 1000
2842, AI-1, 2000
2842, AI-2, 3000
1234, C#3, 2500
1234, C#4, 2700

I want to go through this table find the CenterID check how many time its exist combine value of that CenterID and then send course infromation…

like… I want to send an email that CenterID 1234 have those courses…
1234, C#1, 1000
1234, C#2, 2000
1234, C#3, 2500
1234, C#4, 2700

and then take another CenterID check how many time that exist …combine value and then send course infromation… and so on … how can i do that…

@Ellen
DT3.AsEnumerable.Where(function(r) r(0).ToString.Equals(“1234”)).CopyToDataTable

Hello @Ellen

  1. Read Range: Read your DataTable into dtCourses.
  2. Initialize Variables: Create currentCenterID, previousCenterID, coursesList, and emailBody.
  3. For Each Row: Iterate through dtCourses.
  4. Check CenterID Change: Compare currentCenterID with previousCenterID.
  5. Send Email for Previous Group: If coursesList is not empty, send an email with its contents.
  6. Update Variables: Update previousCenterID and add courses to coursesList.
  7. Final Email (Optional): After the loop, send a final email if coursesList is not empty.
  8. Exception Handling: Implement error handling for email sending failures.

Thanks & Cheers!!!