Ssis 如何将列表内容保存为对象类型

Ssis 如何将列表内容保存为对象类型,ssis,script-component,Ssis,Script Component,我有一个列表/元组,其中填充了一些值。我想将这些值保存到脚本组件中的对象类型变量中。我怎样才能做到这一点。到现在为止,我确实试过了,但没有成功 public class ScriptMain : UserComponent { private List<SomeValues> SomeList = new List<SomeValues>(); public override void PreExecute() { base.Pre

我有一个列表/元组,其中填充了一些值。我想将这些值保存到脚本组件中的对象类型变量中。我怎样才能做到这一点。到现在为止,我确实试过了,但没有成功

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; }
    }

}
public类ScriptMain:UserComponent
{
私有列表SomeList=新列表();
公共覆盖无效预执行()
{
base.PreExecute();
}
公共重写void PostExecute()
{
base.PostExecute();
//试图保存列表的对象类型变量
Variables.LatestDateTime=SomeList;
}
公共覆盖无效Input0\u进程InputRow(Input0Buffer行)
{
var MatchingRow=SomeList.FirstOrDefault(d=>d.Id==Row.Id);
if(MatchingRow==null)
{
添加(新的日期时间值)
{
ID=行。ID,
LatestDateTime=Row.DateTime
});
}
其他的
{
if(MatchingRow.LatestDateTime
您需要先将列表写入datatable,然后将datatable设置为变量

示例-从列表中填充数据表

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);
}

然后,您可以使用foreach ado分子在SSIS中循环对象变量。

您需要先将列表写入datatable,然后将datatable设置为变量

示例-从列表中填充数据表

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);
}

然后,您可以使用foreach ado分子在SSIS中循环对象变量。

非常感谢您的回复。我不知道我是否被允许在同一个线程中提出后续问题,但我们如何才能实现相反的目标list@Ashish看看我的答案-这里我写了如何将一个对象写入列表,在这里你可以看到我是如何完成上面的一些操作的。非常感谢你的回复。我不知道我是否被允许在同一个线程中提出后续问题,但我们如何才能实现相反的目标list@Ashish看看我的答案-这里我写了如何将一个对象写入一个列表,在这里你可以看到我是如何完成上面的一些操作的