将DataTable更改为数组的数组

本文关键字:数组 DataTable | 更新日期: 2023-09-27 17:59:07

我有一个DataTable,它有很多字段。

我想关心这些字段,它们是CampaignHourMinutes

我想获取每个Campaign的数据,然后在数组中添加HourMinutes值,如下所示:

[[Hour, Minute], [Hour, Minute], [Hour, Minute]....[Hour, Minute]]

我试过了

DTgraph是数据表变量。获取所有Campaign:

var compainNames = (from row in DTgraph.AsEnumerable()
                          group row by row.Field<string>("Campaign") into grp
                          select new
                          {
                              CampaignName = grp.Key
                          }).ToList();

然后,获取每个Campaign:的数据

for (int i = 0; i < compainNames.Count(); i++) {
    Int64[][] array = new Int64[][] { };
    var dataForOneCampaint = DTgraph.Select("Campaign = " + compainNames[i].ToString()).ToList();
    for (int j = 0; j < dataForOneCampaint.Count(); j++) { 
        array[1] = ...
    }
}

我知道我可以接受这样的值:

dataForOneCampaint[index].Field<Decimal>("Hour"))

但我不知道如何填写array。你能帮我吗

将DataTable更改为数组的数组

 var compainNames = (from row in DTgraph.AsEnumerable()
                      group row by row.Field<string>("Campaign") into grp
                      select new
                      {
                          CampaignName = grp.Key
                      }).ToList().ToArray();