在SSIS中显示表的交替行
本文关键字:SSIS 显示 | 更新日期: 2023-09-27 18:03:27
我有两个对象,其中包含两个具有相同列名的表。我需要使用ssis中的脚本在邮件正文中显示这些表值。邮件应该包含表1的第一行,下面应该包含表2的行。
下面的查询只显示单个表的值。
oleDA.Fill(Obj_Duration, Dts.Variables["User::Obj_Duration"].Value);
foreach (DataColumn col in Obj_Duration.Columns)
{
Mail = Mail + "<th bgcolor='#7A378B' align='center'><font color='#FFFFFF'>" + col.ColumnName + "</font></th>";
}
foreach (DataRow row in Obj_Duration.Rows )
{
sMail = sMail + "<tr>";
foreach (DataColumn col in Obj_Duration.Columns)
{
sMail = sMail + "<td align = 'center'>" + row[col.Ordinal].ToString() + "</td>";
}
sMail = sMail + "</tr>";
Mail = Mail + sMail;
sMail = "";
Mail = Mail + "<br>";
}
sMail = "";
Mail = Mail + "</table>";
Mail = Mail + "<br>";
需要更改此查询
将第一个表作为foreeach循环遍历,第二个表仅使用第一个表的索引位置来测试该行是否存在并从中检索信息,而不是尝试将该行作为每个循环的a遍历
那么在你的第一个循环末尾添加一些东西,比如:
int i = Obj_Duration.Rows.IndexOf(row);
if (AlternatingDataTableName.Rows.Count - 1 >= i)
{
DataRow alternatingRow = AlternatingDataTableName.Rows[i];
//Start TR
foreach (DataColumn col in AlternatingDataTableName.Columns )
{
//Start TD
//alternatingRow[col.Ordinal].ToString()
//End TD
}
// end TR
}
只是按你想要的方式构建字符串,我放了一些注释来提示你何时可能想要做什么。并将数据表变量的名称更改为第二个Table变量。为了确保你知道我的建议,你的整个代码看起来像这样:
oleDA.Fill(Obj_Duration, Dts.Variables["User::Obj_Duration"].Value);
foreach (DataColumn col in Obj_Duration.Columns)
{
Mail = Mail + "<th bgcolor='#7A378B' align='center'><font color='#FFFFFF'>" + col.ColumnName + "</font></th>";
}
foreach (DataRow row in Obj_Duration.Rows )
{
sMail = sMail + "<tr>";
foreach (DataColumn col in Obj_Duration.Columns)
{
sMail = sMail + "<td align = 'center'>" + row[col.Ordinal].ToString() + "</td>";
}
sMail = sMail + "</tr>";
Mail = Mail + sMail;
sMail = "";
Mail = Mail + "<br>";
int i = Obj_Duration.Rows.IndexOf(row);
if (AlternatingDataTableName.Rows.Count - 1 >= i)
{
DataRow alternatingRow = AlternatingDataTableName.Rows[i];
//Start TR
foreach (DataColumn col in AlternatingDataTableName.Columns )
{
//Start TD
//alternatingRow[col.Ordinal].ToString()
//End TD
}
// end TR
}
}
sMail = "";
Mail = Mail + "</table>";
Mail = Mail + "<br>";
}