My first thought is that you don't need a script task for this. Once you have the SQL, grouped by claim number or whatever you're using to determine uniqueness, then you have the row(s) you need. Using one or more transform tasks you should be able to build out a table structure that has the information needed to then call the Send Mail Task via a foreach container.
But assuming that you do need a script task then converting from a DataTable to a List<Order> is pretty straightforward. I do question whether it might be overkill though given that you could accomplish the same thing just sticking with the DataTable. But let's work with what you already have. I'm going to assume here that you are running a newer version of SSIS such that you can change the script task to run .NET 3.5 or higher so that LINQ is available. This makes it very easy to do. I'm also testing using the newer compiler so the script task compiler may not accept all this as is.
To use LINQ you need to:
- Change the target framework for the script task to .NET 3.5+
- If not already done ensure the script task has a reference to the
System.Core
namespace
//Get the rows grouped by the unique column(s)
//For each group create an order that sets the base order information from the first item and the rest as container
var orders = from r in dt.Rows.OfType<DataRow>()
group r by r.Field<string>("Order_Number") into g
select new Order() {
order_number = g.Key,
claim_number = g.FirstOrDefault().Field<string>("ClaimNumber"),
po_number = g.FirstOrDefault().Field<string>("po_number"),
container = g.Select(x => x.Field<string>("container")).ToList()
};