Here is the sample data
I have to create SSIS package that will send emails that will contain 1 order per email. So based on the above sample, this package will send 2 send emails.
In my Control Flow I have Execute SQL Task and Script Task. From Execute SQL task the data is stored in a variable of type OBJECT and accessed in the Script Task.
My approach is to create Data table to store the data from OBJECT variable, and then loop through and store each order in a object. then when a new order is read then add the Order object in a list. I don't know how to detect when the current row has a new order.
Here is my C# code.
Code Begin
public class Order
{
public string chwhlo { get; set; }
public string order_number { get; set; }
public string claim_number { get; set; }
public string po_number { get; set; }
public string qty { get; set; }
public string purchase_order_price { get; set; }
public string external_charge { get; set; }
//public List<Container> container { get; set; }
public List<string> container { get; set; }
}
public void Main()
{
// TODO: Add your code here
try
{
OleDbDataAdapter oleDA = new OleDbDataAdapter();
//DataSet ds = new DataSet();
//ds = (System.Data.DataSet)Dts.Variables["User::RecordsObject"].Value;
//oleDA.Fill(ds,"Mdata");
DataTable dt = new DataTable();
oleDA.Fill(dt, Dts.Variables["User::RecordsObject"].Value);
//dt = ds.Tables["Mdata"];
//List<string> lst_mtcamu = new List<string>();
StringBuilder subject = new StringBuilder();
Order Ord = new Order();
//Ord.chwhlo = "1";
string previous = "-1";
double purchase_order_price = 0.00;
double external_charge = 0.00;
int recordcount = 0;
List<string> lstOrderNumber = new List<string>();
List<Order> Ordlist = new List<Order>();
string temp = null;
foreach (DataRow row in dt.Rows)
{
// //string RN, Location, Container, Order_Number, ClaimNumber, PONumber, Qty, purchase_order_price, external_charge;
// //Order Ord = new Order();
object[] array = row.ItemArray;
//Ordlist.Add(Ord.chwhlo.ToString());
if (lstOrderNumber.Contains(array[3].ToString()) == false)
{
lstOrderNumber.Add(array[3].ToString());
Ord.order_number = array[3].ToString();
Ord.claim_number = array[4].ToString();
Ord.po_number = array[5].ToString();
temp = array[3].ToString();
MessageBox.Show(Ord.order_number.ToString());
//MessageBox.Show(array[3].ToString());
//Ordlist.Add(Ord);
//MessageBox.Show(Ordlist.Count.ToString());
}
if (temp == array[3].ToString())
{
Ord.container.Add(array[2].ToString());
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Code End