标签:datatable dataview totable rowfilter 过滤
DataTable tab = new DataTable();
tab = DBUtil.GetDataSet(strCmd, "TESTA.V_YHJ_VIP_WX_XSMX").Tables[0];
创建一个小表:
DataView view = new DataView(tab);
DataTable orderTable = view.ToTable(true, "ORDERDATE", "MEMBER_CODE", "INV_NUM", "ZJE", "ZFJE", "SELL_QTY", "SHOP_CODE");
在基于orderTable 的str_Inv_Num ,生成更小的一个表
for (int i = 0; i < orderTable.Rows.Count; i++)
{
for (int j = 0; j < orderTable.Columns.Count; j++)
{
if (j == 0)
{
str_INV_DATE = orderTable.Rows[i][j].ToString().Trim();
//shop_code = tab.Rows[i][j].ToString();
}
if (j == 1)
str_MemberCode = orderTable.Rows[i][j].ToString().Trim();
if (j == 2)
{
str_Inv_Num = orderTable.Rows[i][j].ToString().Trim();
subInv_Num = str_Inv_Num;
}
if (j == 3)
Inv_Totalamt = Convert.ToInt32(orderTable.Rows[i][j].ToString().Trim());
if (j == 4)
str_INV_AMT = Convert.ToInt32(orderTable.Rows[i][j].ToString().Trim());
if (j == 5)
int_Sell_Qty = Convert.ToInt32(orderTable.Rows[i][j].ToString().Trim());
if (j == 6)
str_Shop_Code = tab.Rows[i][j].ToString().Trim();
}
if (str_old_Inv_Num.Trim()!=str_Inv_Num.Trim()) //去除某个会员有2个以上单据,并且每个单据有多件销售货品时的重复记录。目前第一个单号的第一件货品,就会把货品信息都列出来,如果一个单子有多件货品,不加此句就会出现重复数据。导致结果不对。
{
view.RowFilter = "INV_NUM=‘" + str_Inv_Num+"‘";
orderDetailTable = view.ToTable(true, "INV_NUM", "SKU", "C_SHORT_DE", "SELL_QTY", "SERIAL_NO");
List<CofflineOrderDetail> lCofflineOrderDetail = DBUtil.GetList<CofflineOrderDetail>(orderDetailTable);//返回泛型列表
//OracleAccess.logger.Debug(" CAL_getOfflineOrder 子 table :" + str_vip.ToString() + DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString() +
// "," + str_INV_DATE + "," + str_MemberCode + "," + str_Inv_Num + "," + Inv_Totalamt + "," + str_INV_AMT + "," + int_Sell_Qty + "," + str_Shop_Code +
// DBUtil.ToJson(subtab));
listorder.Add(new COfflineOrder(str_INV_DATE, str_MemberCode, str_Inv_Num, Inv_Totalamt, str_INV_AMT, str_Shop_Code, int_Sell_Qty, lCofflineOrderDetail));
view.RowFilter = "";
str_old_Inv_Num = str_Inv_Num;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
在一个大DataTable的基础上去除重复数据,分别创建2个小DataTable,省去多次数据库连接,提高效率,加快程序运行
标签:datatable dataview totable rowfilter 过滤
原文地址:http://blog.csdn.net/handsome1234/article/details/47349063