我有一个列表/元组,我已经填充了一些值。我想将这些值保存到脚本组件中的OBJECT类型的变量中。我怎样才能做到这一点。直到现在我都尝试了这个并没有成功。
public class ScriptMain : UserComponent
{
private List<SomeValues> SomeList = new List<SomeValues>();
public override void PreExecute()
{
base.PreExecute();
}
public override void PostExecute()
{
base.PostExecute();
//Object type variable in which I am trying to save list
Variables.LatestDateTime = SomeList;
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
var MatchingRow = SomeList.FirstOrDefault(d => d.Id == Row.Id);
if (MatchingRow == null)
{
SomeList.Add(new DateTimeValues
{
ID = Row.ID,
LatestDateTime = Row.DateTime
});
}
else
{
if (MatchingRow.LatestDateTime < Row.DateTime)
{
MatchingRow.LatestDateTime = Row.DateTime;
}
}
}
public class SomeValues
{
public int Id { get; set; }
public DateTime LatestDateTime { get; set; }
}
}
答案 0 :(得分:3)
您需要先将列表写入数据表,然后将数据表设置为变量..
示例 - 从列表中填充数据
List<string> cities = new List<string>();
cities.Add("New York");
cities.Add("Mumbai");
DataTable dt = new DataTable();
dt.Columns.Add("column1", typeof (string));
foreach (string str in cities)
{
DataRow row = dt.NewRow();
row["column1"] = str;
dt.Rows.Add(row);
}
将数据表写入对象变量
Dts.Variables["User::NameList"].Value = dt;
然后你可以使用foreach ado numerator来循环SSIS中的对象变量。