HI,
My main objective is:
1. To read the object which I get through Execite Sql task
2. Then Using Script task I want to mail it ,but I need to format the values in object in form of table as the body of mail.
3. And IF Time TimeDifference Column had value =<100 Then Row should be Green Else Red.
![]()
So I have an Object called "ResultSet",I pass to Script Task, I convert it into c# table structure and place it in a variable called "ApplicationTotal". Below is the code for that which works fine.
public void Main()
{
DataTable dtTotal = new DataTable();
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataTable dt = new DataTable();
adapter.Fill(dt, Dts.Variables["InactiveSet"].Value);
// In the first Run dtTotal is created
if (Convert.ToInt32(Dts.Variables["InsertedRowCountTotal"].Value) == 0)
{
foreach (DataColumn dc in dt.Columns)
{
dtTotal.Columns.Add(dc.ColumnName,dc.DataType);
}
}
else // In the next runs dtTotal is retrieved from variable
{
dtTotal = (DataTable)Dts.Variables["InactiveSetTotal"].Value;
}
foreach (DataRow dr in dt.Rows)
{
DataRow newDR = dtTotal.NewRow();
foreach( DataColumn dc in dt.Columns)
{
newDR[dc.ColumnName] = dr[dc.ColumnName];
}
dtTotal.Rows.Add(newDR);
}
Dts.Variables["InactiveSetTotal"].Value = dtTotal;
Dts.Variables["InsertedRowCountTotal"].Value = Convert.ToInt32(Dts.Variables["InsertedRowCountTotal"].Value) + Convert.ToInt32(Dts.Variables["InsertedRowCount"].Value);
Dts.TaskResult = (int)ScriptResults.Success;
}
Then I pass ApplicationTotal object to script task where i have to read the object and mail the details in form of table.I am successful in sending mail but I am not able to format the data in table and change the colour
I get the output in mail as
![enter image description here]()
if (Convert.ToInt32(Dts.Variables["InsertedRowCount"].Value) == 0)
{
return;
}
#region BuildingEmailBody
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("Monitor Application Report"));
sb.AppendLine();
sb.AppendLine();
//sb.AppendLine(string.Format("Following are the Details:\n\n<TABLE><TR>\n<TH>{0}</TH><TH>{1}</TH><TH>{2}</TH> <TH>{3}</TH> <TH>{4}</TH>\n</TR>\n", "TimeDifferences(Minutes) ", "UpdateTime", "ApplicationName", "ServerName", "DatabaseName"));
OleDbDataAdapter adapter = new OleDbDataAdapter();
if (Convert.ToInt32(Dts.Variables["InsertedRowCount"].Value) > 0)
{
sb.AppendLine();
DataTable ApplicationTotal = new DataTable();
ApplicationTotal = (DataTable)Dts.Variables["ApplicationTotal"].Value;
foreach (DataRow dr in ApplicationTotal.Rows)
{
sb.AppendLine(string.Format("{0} {1} {2} {3} {4} ", dr[0], dr[1], dr[2], dr[3], dr[4]));
}
sb.AppendLine();
}
# endregion