20180519001 - DataTable Group by功能参考

Posted 我的梦会回来

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20180519001 - DataTable Group by功能参考相关的知识,希望对你有一定的参考价值。

DataSet6 = DataSet1.Copy();

DataRow[] dr = DataSet6.Tables[0].Select(" 完工状态 = ‘完工异常‘ ");

DataTable dt1 = DataSet6.Tables[0].Clone();

for (int i = 0; i < dr.Length; i++)
{
dt1.ImportRow((DataRow)dr[i]);

//this.Text = i.ToString();
}

 

// Group by
DataTable dtResult = dt1.Clone();
DataTable dtName = dt1.DefaultView.ToTable(true, "委外发票号", "委外订单号", "存货编码", "工艺名称", "订单数量", "出库数量", "未交数量", "CT不良数", "原币含税单价",
"原币价税合计", "累计开票金额", "币种");
for (int i = 0; i < dtName.Rows.Count; i++)
{
DataRow[] rows = dt1.Select(" 委外发票号 =‘" + dtName.Rows[i]["委外发票号"].ToString()
+ "‘ and 委外订单号=‘" + dtName.Rows[i]["委外订单号"].ToString()
+ "‘ and 存货编码=‘" + dtName.Rows[i]["存货编码"].ToString()
+ "‘ and 工艺名称=‘" + dtName.Rows[i]["工艺名称"].ToString() + "‘ ");
//temp用来存储筛选出来的数据
DataTable temp = dtResult.Clone();
foreach (DataRow row in rows)
{
temp.Rows.Add(row.ItemArray);
}

DataRow dr2 = dtResult.NewRow();
dr2["委外发票号"] = dtName.Rows[i]["委外发票号"].ToString();
dr2["委外订单号"] = dtName.Rows[i]["委外订单号"].ToString();
dr2["存货编码"] = dtName.Rows[i]["存货编码"].ToString();
dr2["工艺名称"] = dtName.Rows[i]["工艺名称"].ToString();
dr2["订单数量"] = dtName.Rows[i]["订单数量"].ToString();
dr2["出库数量"] = dtName.Rows[i]["出库数量"].ToString();
dr2["未交数量"] = dtName.Rows[i]["未交数量"].ToString();
dr2["CT不良数"] = dtName.Rows[i]["长腾不良数"].ToString();
dr2["原币含税单价"] = dtName.Rows[i]["原币含税单价"].ToString();
dr2["原币价税合计"] = dtName.Rows[i]["原币价税合计"].ToString();
dr2["累计开票金额"] = dtName.Rows[i]["累计开票金额"].ToString();

dr2["币种"] = dtName.Rows[i]["币种"].ToString();

dr2["入库数量"] = temp.Compute("sum(入库数量)", "");
dtResult.Rows.Add(dr2);
}


//
DataSet9 = new DataSet();
DataSet9.Tables.Add(dtResult);

以上是关于20180519001 - DataTable Group by功能参考的主要内容,如果未能解决你的问题,请参考以下文章

C# DataTable怎么合计字段

NPOI DataTable导出excel

动态 Javascript 源数据 - DataTable

List转换DataTable

一个200行数据的datatable大概占用多少内存?

jquery dataTable分页没有出现