首页 新闻 会员 周边 捐助

Hi,All.How to Convert Anonymous(var) Type to DataTable Type?

0
悬赏园豆:5 [已关闭问题] 关闭于 2016-12-23 13:22
                
                System.Data.DataTable oldDataTable = new DataTable();
        oldDataTable.Columns.Add("CheckinNum");
        oldDataTable.Columns.Add("CustomerAmount");
        oldDataTable.Columns.Add("ProviderAmount");
        oldDataTable.Columns.Add("AgentAmount");
        oldDataTable.Columns.Add("GrossAmount");
        oldDataTable.Columns.Add("TheMonth");

        int N=17; 

        System.Data.DataRow dr = oldDataTable.NewRow(); 
        for (int i = 1; i < N; i++)
        {
            dr = oldDataTable.NewRow();
            dr["CheckinNum"] = 1;
            dr["CustomerAmount"] = 2;
            dr["ProviderAmount"] = 3;
            dr["AgentAmount"] = 4;
            dr["GrossAmount"] = 5;
            dr["TheMonth"] = i<=12?i:1;
            oldDataTable.Rows.Add(dr);
        }                
                
                for (var i = 1; i <= 12; i++)
            {
                oldDataTable.Rows.Add(0, 0, 0, 0, 0, i);
            }
            var haha = oldDataTable.Rows.Cast<DataRow>().GroupBy(x => x["TheMonth"])
                    .Select(x => new
                    {
                            TheMonth = x.Key,
                            CheckinNum = x.Sum(x1 => Convert.ToInt32(x1["CheckinNum"])),
                            CustomerAmount = x.Sum(x1 => Convert.ToInt32(x1["CustomerAmount"])),
                            ProviderAmount = x.Sum(x1 => Convert.ToInt32(x1["ProviderAmount"])),
                            AgentAmount = x.Sum(x1 => Convert.ToInt32(x1["AgentAmount"])),
                            GrossAmount = x.Sum(x1 => Convert.ToInt32(x1["GrossAmount"]))
                    }).ToList();
                    
            //TODO : Convert haha to DataTable Type.
                                
                                
                                
                                
                                
                                
alone2013的主页 alone2013 | 初学一级 | 园豆:46
提问于:2014-01-19 13:08
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册